Is there an equivalent function in JavaScript or jQuery similar to strpos in PHP?
I want to locate a string inside an element on a page. The string I\'m
You don't need jquery for this -- plain old Javascript will do just fine, using the .indexof() method.
However if you really want an exact syntax match for PHP's strpos(), something like this would do it:
function strpos (haystack, needle, offset) {
var i = (haystack+'').indexOf(needle, (offset || 0));
return i === -1 ? false : i;
}
Note: This function taken from here: http://phpjs.org/functions/strpos:545
JSFiddle