jQuery find attribute from url hash -


trying find attribute value url hash.

// url http://url.com/index.html#link  // html <a href="#link" rel="3">some link</a>  // js var anchor = window.location.hash.substring(1); // need finding attribute value finding anchor var attribute = .find('#+anchor').attr('rel'); //this needs have value of 3 

all appreciated. :)

you can using attribute-equals selector, this:

$('a[href="'+window.location.hash+'"]').attr("rel") 

or .filter(), this:

$("a").filter(function() { return this.hash == location.hash; }).attr("rel") 

the .hash starting # consistent, no need remove/add back, use as-is.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -