1. Gatzby

    What does jQuery have to do with any of this? The whole point of your story, checking if the URL contains a certain string, is done entirely without jQuery. The indexOf method is native JavaScript. Are you really going to load several kilobytes of jQuery to do something as trivial as this?

    Remember: jQuery == JavaScript.

  2. Hi,

    I’m not sure if I’ve misunderstood you, but using the .indexOf method isn’t jQuery specific, but something that’s been part of JavaScript since version 1.0.

    If the substring exists, then it’s position in the string is returned – the first position being 0 like the first element of an array. If no occurance of the substring is found then -1 is returned.

    Your example code looks correct, but the Developer Note below it is ambiguous.

    If the code is going to be frequently run in a tight loop, then a slight performance increase could be to use an inverted identity comparison !== -1 rather than > -1.

Leave a Reply