If you look at the selectors list on the jQuery website, there are selectors for starts-with and ends-with on attributes. There's also a :contains
selector for searching text:
alert( $("div").find("span:contains(text)").html() );
Does jQuery have an implementation for searching strings using starts-with or ends-with?
FYI: I need to search through an XML object.
When you don't want to extend jQuery, you can use the
filter()
function to create the contains functionality:Or create a startsWith function with a regular expression:
The endsWith function is quite similar:
Note the use of
$.trim()
because HTML can contain a lot of whitespace.Not by default as far as I know, but you can add your own pseudo-selectors through
$.expr[":"]
: http://jsfiddle.net/h6KYk/.