Would it be wiser to check if a particular element exists on the page?
if ($('#cool-page').length > 0) {
// my jQuery function
}
Or check if the window location is the correct page?
if (window.location.href.indexOf('words-here') != -1) {
// my jQuery function
}
In this situation, I only want to run my jQuery function on pages: site.com/123/words-here
If the best way is the latter, how should I be writing up a regexp to match the location above?