bostboy — 2010-11-03T14:41:26-04:00 — #1
The code below works fine in Firefox but doesn't work in IE8. Is that to be expected and if so, why?
if (($(this).children(a).text()) == 'Hide')
If I change it to -- if ($('.accordionShow .head a').text() == 'Hide') it works fine but I lose the ability to use 'this', which I would like to have.
The HTML is
<h2 class="head"><a href="#">Hide</a> the Section</h2>
What I want to do is be able to identify the label as Hide or Show without getting the whole text, i.e. 'Hide the Section'. That way no matter what the label is it will work the same. And I could substring it I suppose by using the text of the <h2> tag but it seems that is unnecessary also.
Is this just another peculiarity of IE, that it doesn't use the .children(a) selector?
bostboy — 2010-11-03T14:52:18-04:00 — #2
I found it. IE is a little more stringent and requires the use of quotes around the a as in
if (($(this).children('a').text()) == 'Hide')
and then it seems to work fine.
If anyone can confirm that independently that would be great. Thanks
pavel_nedved — 2010-11-03T15:30:05-04:00 — #3
Yep, you should be using quotes. Firefox probably should have failed without them.
bostboy — 2010-11-03T15:37:37-04:00 — #4
Thanks for confirming that. I appreciate it.