Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find label starting with text with jQuery

I have some labels, like:

<label>Some words</label>
<label>Some other words</label>
<label>Yet another words</label>

How can I get labels starting with "Some" (or other text?). I tried

$("label").filter('html^="Some"')
//or
$("label").filter('text^="Some"')

but it doesn't seem to work (returns empty list). It's more complicated in my real problem so maybe I made some other mistake, but maybe I'm doing it totally wrong? Is any of these a good way to do it? What's the best way?

like image 895
Episodex Avatar asked Oct 21 '11 12:10

Episodex


1 Answers

I would do this (jsfiddle):

$('label').filter(function(index) {
  return $(this).text().search('Some') == 0;
})...
like image 145
bozdoz Avatar answered Sep 20 '22 05:09

bozdoz