Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - select element starting and ending with... but omit specific name

I have elements generated on my board that have IDs like so "test_***_fast". The 3 stars are random numbers generated by the site.

Problem is that I want to write an action for all IDs except for test_1_fast, because this one is static and important.

I know I can't use:

$('[id^=test][id$=_fast]')

because it works for test_1_fast as well and code blow obviously doesn't work :D

 $('[id^=test][id$=_fast]' - '#test_1_fast')

So how should I put this to make it work?

like image 853
Ventricle Avatar asked Jan 17 '26 19:01

Ventricle


1 Answers

Use :not() for avoiding certain element

$('[id^=test][id$=_fast]:not(#test_1_fast)').css('color', 'red')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>


<span id="test_0_fast">a</span>
<span id="test_1_fast">a</span>
<span id="test_2_fast">a</span>

or not()

$('[id^=test][id$=_fast]').not('#test_1_fast').css('color', 'red')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>


<span id="test_0_fast">a</span>
<span id="test_1_fast">a</span>
<span id="test_2_fast">a</span>
like image 90
Pranav C Balan Avatar answered Jan 20 '26 08:01

Pranav C Balan