Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    138
    Thanks
    1
    Thanked 1 Time in 1 Post

    Having problems scrolling to 'Y' position

    I have not been having luck with jQuery lately.

    All I am trying to do is find a specific span tag (which i did) and then find its position in the parent div and scroll to that point.

    The alerts below simply return '0'.
    Code:
    var elemnt = $('#glossaryContent').find('span:contains(' + evt + ')');
    alert(elemnt.text());
    var location = elemnt.offset().top;
    alert(location);
    var term = $('#glossaryContent').find('span:contains(' + evt + ')').scrollTop();
    alert(term);

  • #2
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    415
    Thanks
    10
    Thanked 61 Times in 60 Posts
    I didn't know there was a CSS pseudo class :contains, and as I search the w3c reference this has already been deprecated.

    Nevertheless jQuery implements it and so perhaps your line should be something like below, or the reverse (flip the double-quotes with the singles):
    Code:
    .find('span:contains("' + evt + '")')

  • #3
    Regular Coder
    Join Date
    Jun 2012
    Posts
    138
    Thanks
    1
    Thanked 1 Time in 1 Post
    Quote Originally Posted by hdewantara View Post
    I didn't know there was a CSS pseudo class :contains, and as I search the w3c reference this has already been deprecated.

    Nevertheless jQuery implements it and so perhaps your line should be something like below, or the reverse (flip the double-quotes with the singles):
    Code:
    .find('span:contains("' + evt + '")')
    Still not working. Returns zero no matter which term I chose.

  • #4
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    415
    Thanks
    10
    Thanked 61 Times in 60 Posts
    Is it possible the span just doesn't contain the exact 'evt' term? Maybe some letters are in uppercase. Could you paste a bit of the HTML structure here?

  • #5
    Regular Coder
    Join Date
    Jun 2012
    Posts
    138
    Thanks
    1
    Thanked 1 Time in 1 Post
    Quote Originally Posted by hdewantara View Post
    Is it possible the span just doesn't contain the exact 'evt' term? Maybe some letters are in uppercase. Could you paste a bit of the HTML structure here?
    The user clicks on the link below and, in this case, 'GSU' is passed to the javascript. So I believe all is well with that part but here is the html:
    Code:
    <a class="glossaryLink" href="#" onmouseover="onRollOverPULink(event, 'GSU');"onmouseout="onRollOutPULink(event);" onclick="showHideGlossary('GSU')">GSU</a>
    And here is the JS that populates the glossary div:
    Code:
    $("#glossaryContent").append("<span class='glossAcro'>" + $(this).attr('term') + "</span>" + "<span class='glossDef'>" + $(this).attr('def') + "</span>"); // output from XML
    And here is part of the XML file which is the source for the glossary:
    Code:
    <item term="GIG" def="Global Information Grid" />
    
    <item term="GSU" def="Geographically Seperated Unit" />
    By the way, thanks for the help.


  •  

    Posting Permissions

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