Skip to content

Instantly share code, notes, and snippets.

@johngag
Created December 4, 2012 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johngag/4209311 to your computer and use it in GitHub Desktop.
Save johngag/4209311 to your computer and use it in GitHub Desktop.
jQuery starts-with and ends-with
$.extend($.expr[":"], {
"starts-with": function(elem, i, data, set) {
var text = $.trim($(elem).text()),
term = data[3];
return text.indexOf(term) === 0;
},
"ends-with": function(elem, i, data, set) {
var text = $.trim($(elem).text()),
term = data[3];
return text.lastIndexOf(term) === text.length - term.length;
}
});
//Example
$("div:starts-with('inserttext')");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment