Example:
http://jsfiddle.net/dfcyb/
I have these two vars
var inview = '#' + $("#container > .section > h1:in-viewport:first").parent().attr('id');
var $link = $('#menu a').filter('a[hash=' + inview + ']');
inview checks to see if a particular section is in the viewport and then using the $link var to add a class. I’m not sure what I’m doing wrong here. Inview is working fine but:
$link.parent().addClass('selected');
does nothing. I’m not really sure what I have wrong here or how to go about debugging since console.log($link) isn’t helpful. I’m not sure if filter is being used right here?
a[hash=should bea[href$=Where
$=means ends with.Replace:
With:
Source: http://api.jquery.com/attribute-ends-with-selector/