Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add class with jQuery for ends

i have:

<span id="asdfasdf_test">
<span id="adfaf_test33">
<span id="2342_test">
<span id="34223sdf_testrr">
<span id="asdfsdsdf_test">
<span id="asdf2343sdf_test">

.red {
color: red
}

if span id ends at _test i would like add for this span class .red . how can i make this with jQuery?

LIVE EXAMPLE: http://jsfiddle.net/X6TTd/

like image 739
Paul Attuck Avatar asked Mar 25 '26 10:03

Paul Attuck


1 Answers

$('span[id$="_test"]').addClass('red');

The $= attribute selector means 'ends with'. I added "span" to the jQuery selector since they are all spans in your example, but you can also select the attribute on any element:

$('[id$="_test"]')
like image 114
Chris Pratt Avatar answered Mar 27 '26 00:03

Chris Pratt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!