Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  30] [ 4]  / answers: 1 / hits: 16280  / 12 Years ago, fri, september 21, 2012, 12:00:00

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')
});

More From » jquery

 Answers
15

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');
}
});

[#82966] Thursday, September 20, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stacyl

Total Points: 131
Total Questions: 105
Total Answers: 94

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago
;