Search code examples
jqueryurlcontain

jquery: if url contains #work then do something


I tried to write a script which allow me to load certain events when I enter specific url.

My code looks like this:

$(function(){
    var url = window.location.pathname;
    $("url:contains('#Work')").animate({"left": "250"}, "slow");
});

But it doesnt work. Any suggestions? Any help is appreciated.


Solution

  • $(function() {
        if ( document.location.href.indexOf('#Work') > -1 ) {
            $('#elementID').animate({"left": "250"}, "slow");
        }
    });