How to apply jquery UI effect to #name element from URL
I'd like to apply a query UI effect to an element depending on the # from the URL.
i.e.: When loading www.mysite.com/page.html#name, effect() is applied to the element with the #name id while loading www.mysite.com/page.html#othername would have effect() apllied to the element with the #othername id and www.mysite.com/page03.html would simply have no effect() ap开发者_StackOverflow中文版plied.
You can use
window.location.hash
to get the part of the URL that follows the # symbol, including the # symbol.
See window.location
In your case it will return #name
.
$(function(){
$("#btn1").click(function( ){
var elemName = window.location.hash;
/* $(elemName) will retrieve the jQuery element with the corresponding
id and you can apply the effect to this element.*/
});
});
精彩评论