Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-20-2013, 06:34 PM   PM User | #1
m2244
Regular Coder

 
Join Date: Jun 2012
Posts: 129
Thanks: 1
Thanked 1 Time in 1 Post
m2244 is an unknown quantity at this point
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);
m2244 is offline   Reply With Quote
Old 02-21-2013, 09:15 AM   PM User | #2
hdewantara
Regular Coder

 
hdewantara's Avatar
 
Join Date: Aug 2009
Location: Jakarta, Indonesia.
Posts: 289
Thanks: 5
Thanked 40 Times in 40 Posts
hdewantara is an unknown quantity at this point
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 + '")')
hdewantara is offline   Reply With Quote
Old 02-21-2013, 01:42 PM   PM User | #3
m2244
Regular Coder

 
Join Date: Jun 2012
Posts: 129
Thanks: 1
Thanked 1 Time in 1 Post
m2244 is an unknown quantity at this point
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.
m2244 is offline   Reply With Quote
Old 02-21-2013, 05:04 PM   PM User | #4
hdewantara
Regular Coder

 
hdewantara's Avatar
 
Join Date: Aug 2009
Location: Jakarta, Indonesia.
Posts: 289
Thanks: 5
Thanked 40 Times in 40 Posts
hdewantara is an unknown quantity at this point
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?
hdewantara is offline   Reply With Quote
Old 02-21-2013, 05:30 PM   PM User | #5
m2244
Regular Coder

 
Join Date: Jun 2012
Posts: 129
Thanks: 1
Thanked 1 Time in 1 Post
m2244 is an unknown quantity at this point
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.
m2244 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:25 PM.


Advertisement
Log in to turn off these ads.