SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using $(this).children(a) with IE vs Mozilla

    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

    <div class="accordionShow">
    <h2 class="head"><a href="#">Hide</a> the Section</h2>
    </div>

    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?

  2. #2
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  3. #3
    SitePoint Addict Pavel_Nedved's Avatar
    Join Date
    Aug 2004
    Location
    Victoria, BC
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, you should be using quotes. Firefox probably should have failed without them.

  4. #4
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for confirming that. I appreciate it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •