the url is as this: http://example.com/download/
var pathname = window.location.pathname;
if(pathname=='download/'){
$("#subnav-content div:first").hide();
$("#subnav-content div:second").show();
}
why the above code in jquery doesn’t work? i want to when the url is http://example.com/download/. show the secong div.
ps*:does this check affect the site performance?*
You need the leading slash.
‘/download/’
If you expect query string parameters you may try a regular expression to just match the download portion of the url: the following matches /download/.
Regarding the jquery, there is no :second, you need to use :eq(1)
Response to comments
I’m putting my comment here because the formatting is horrible in the comments. The regular expression for matching download can be summed up as follows:
/– start of regular expression matching syntax^– means start matching at the very start of the screen\/– means match the literal string ‘/’, which is a special character which must be escapeddownload– match the literal string ‘download’\/– again means match the literal string ‘/’/– end of the matching syntaxi– regular expression options, i means ignore caseIt was not clear to me what your other note was asking for.