Is there a "start by" filter in jQuery, something like :contain but with a string beginning condition ?
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")
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) }
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With