Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If URL contains string then run jQuery function?

On my website id like to run a jQuery function if my url contains the word 'test'

All im trying to do is if my url contains the 'rest' string then add a margin to an element on the page?

Ive added a jSfiddle to try and show what Ive done so far.

$(document).ready(function(){         
    // How can I check to see if my url contains the word 'TEST' then run the below function?
    $('.block-widget').css('margin-top, 252px')     
});
like image 537
Liam Avatar asked Dec 20 '22 16:12

Liam


1 Answers

Use window.location to get the current location url..

Based on the condition you can then apply the margin top property.

$(document).ready(function(){         
     var pathname = window.location.pathname;
     if(pathname.indexOf('text') > -1){
        $('.block-widget').css('margin-top, 252px');
     }     
});
like image 174
Sushanth -- Avatar answered Dec 30 '22 13:12

Sushanth --