Is there a "start by" filter in jQuery, something like :contain but with a string beginning condition ?
A:
Start With: ^=
The ^= operator will filter elements whose attribute starts with the given value.
More info here:
http://www.bennadel.com/blog/1003-Cool-jQuery-Predicate-Selectors.htm
Aseem Gautam
2010-01-06 10:53:32
These selectors are useful, but they're for attributes, not for content.
Kobi
2010-01-06 11:01:45
+2
A:
Not that I know of, but you can easily implement your own selector for jQuery:
$.extend($.expr[':'], {
startsWith: function(elem,match) {
return (elem.textContent || elem.innerText || "").indexOf(match[3]) == 0;
}
});
Now you can use it like this:
$("p:startsWith(Hello)").css("color","red")
duckyflip
2010-01-06 10:56:58
Thanks, and with cas insensitive :// case insenstitive for live :contain$.extend($.expr[":"], { "startWith": function(elem, i, match, array) { return (elem.textContent || elem.innerText || "").toLowerCase ().indexOf((match[3] || "").toLowerCase()) == 0; }});
adrien334
2010-01-06 12:44:31
A:
No, but you can do it yourself using filter
, as pulse suggested:
$('a').filter(function(){
return $(this).text().indexOf('start') == 0 }
)
You may want to use a regular expression here, to ignore case, or for more advanced searches:
$('a').filter(function(){
return $(this).text().match(/^start/i) }
)
Kobi
2010-01-06 10:59:21