Using Firebug Lite in IE 7, with jQuery 1.4.4. I'm trying to grab all the ".step" <div/> elements that are not the first one (there are 2 or 3 now, but assume an arbitrary amount of steps). Works in FF and Webkit, but noticed the same selector of :not with :first does not select the same items in IE7. jQuery bug? Should this work? Can you suggest an alternative way to select these items?
# Firebug Lite console
>>> $('.step')
[div#step_1.step, div#step_2.step, div#step_3.step]
>>> $('.step:first')
[div#step_1.step]
>>> $('.step:not(:first)')
[div#step_1.step, div#step_2.step, div#step_3.step]
This isn't an answer to the IE7 issue, but it is a workaround, and probably a better way to do it overall.
Instead of:
$('.step:not(:first)')
do this:
$('.step').slice(1);
Now you're using a simple selector that is valid for querySelectorAll, and simply paring it down to all but the first match.
Overall it should perform better for you.
EDIT:
There does seem to be an open bug with regard to :not(:first) in IE 7.
Here's the link: http://bugs.jquery.com/ticket/4028
You could use
$('.step:gt(0)')
don't have an IE7 handy to test at the moment though
The .not() method is recommended over the :not pseudo-class selector in the jQuery documentation for readability, but :not also has terrible performance consequences. Omitting tag-names does as well in many cases. Testing in IE8, I found the .not() method about thirty-four times faster than the :not pseudo-class selector.
I concur with user113716 that the .slice method is probably best here, but for those having trouble with :not in a similar situation, I would suggest something like this:
$('div.step').not('div:first')
Related
I am using this:
document.getElementById("div").getElementsByClassName("class");
The above seems to work in Chrome and FireFox, but not in IE8.
I am using
document.getElementById("branch").getElementsByClassName("branch.address");
Above one fetches one row but using this
document.getElementById("branch").querySelectorAll("branch.address");
fetched empty
How do I make this work in IE8?
The problem isn't getElementById, it's getElementsByClassName — IE8 doesn't have that.
Instead, you can use querySelectorAll, which is on all modern browsers, and also IE8:
document.getElementById("div").querySelectorAll(".class");
Or all in one:
document.querySelectorAll("#div .class");
querySelectorAll accepts any CSS selector, and returns a list of matching elements. There's also querySelector, which accepts any CSS selector, and returns the first matching element (or null if none match).
IE8 does not support getElementsByClassName(). See this post for more details. Also see the link posted here for a SO post with work-arounds.
Is there a known solution to do CSS selectors like this one in Selenium?
$('.sss').find('>div.ui-collapsible-content')
works fine on Chrome developer tools.
In Selnenium it throws exception
OpenQA.Selenium.InvalidElementStateException : invalid element state: Failed to execute 'querySelector' on 'Element': '>div.ui-collapsible-content' is not a valid selector.
(Session info: chrome=33.0.1750.154)
(Driver info: chromedriver=2.8.241075,platform=Windows NT 6.1 SP1 x86)
I could just use selector without parent part
.find('div.ui-collapsible-content')
and only take first element, but this is somewhat hacky solution and someone must have ran into similar situation by now and found more elegant solution than this.
jsfiddle HTML example - http://jsfiddle.net/uHYZL/1/
I wouldn't call this a limitation. This looks like expected behaviour to me, as I don't see >div.ui-collapsible-content being a valid CSS selector in the first place.
The reason $('.sss').find('>div.ui-collapsible-content') works is because you are using jQuery, which uses Sizzle as the CSS selecting engine under the hood. It supports things that W3C spec doesn't support, like :contains() etc.
I'm not sure what you are trying to achieve here. Wouldn't something like below suit you needs?
var content = driver.FindElement(By.CssSelector(".sss > div.ui-collapsible-content"));
Have you tried using Xpath? It would look pretty horrible and complex but I am sure you could construct a selector which would only find parents, then continue from there.
i would try and construct one but don't have access to a computer currently
In internet explorer 8, emit strange jquery attributes that sometimes can cause problem and when I need to select them, the selector won't work.
I don't know if this is related to my rendering problem, but I've never noticed it before, in IE8 or any other browser. Can someone explain what these attributes are?
sizzle-1377765392290 ="[object Object]"
also it creates unique id for each element
i.e: jQuery110201441698622493836
https://www.dropbox.com/s/e5l0r9weht23mhn/Ie8.PNG
Thanks You
See the answer here, jQuery uses it to attach event handlers etc in IE.: https://stackoverflow.com/a/16341470/1371408
As i can see in this bugs.jquery.com/ticket/8539 that sizzle cache bug was fixed in 1.7 version of jquery .
And as per your comment you included older version of jquery 1.1.0 so updating it to latest release of jquery will solve your issue .
You can remove this by,
var re = /\s*(sizset|sizcache)\d*="[^"]*"/gi;
source = source.replace(re,'');
http://jsfiddle.net/mblase75/fMdVc/
Alternatively, jQuery has a .removeAttr() method, but you'll have to apply it to specific tags:
jQobj.removeAttr('sizset').removeAttr('sizcache');
Have a look
$(window.frames['myframe'].document.getElementById('frameid'))
This statement sometimes returns null in Firefox but working properly in any other browsers. What can be the problem ?
Thanks in advance,
By the looks of it you simply need to change the selector it should be
$('#myframe').contents().find('#frameid').html();
JQuery handles the finding of it, take a look at selectors in jQuery
Selectors
I have a very strange problem. Under some elusive circumstances I fail to apply any jQuery selector on my pages under IE. It's OK under Firefox though. The jQuery function simply returns empty array.
Any suggestions?
Page is too complex to post it here. Practically any selector, except "#id" selectors, returns a zero element array. The jQuery version is 1.2.3
What version(s) of IE is it failing under? Is it failing for a specific complex selector? I think we need an example.
Edit: Does the problem go away if you upgrade to 1.2.6? 1.2.6 is primarily a bug-fix release according to this page.
Failing that, the best way to find the problem is to create a minimum page that can reproduce the bug. Without that, it's just about impossible to troubleshoot.
Try upgrading to jQuery 1.2.6, you should be on the latest release of jQuery if you are having problems first ensure you are on the latest and greatest.