You can loop through all elements where id
contains med_date
Like this :
$( $('[id^=med_date_]') ).each(function() {
Can you do it by id
and class
, something like this
$( $('[id^=med_date_] [class^=med_group_]') ).each(function() {
The id can be med_date_1, med_date_2, med_date_3, etc
same for the class med_group_1, med_group_2, med_group_3, etc.
Yes sure you've just to remove the space between the selectors like :
$('[id^=med_date_][class^=med_group_]')
That the selector for class AND id, if you want class OR id you could use comma separator :
$('[id^=med_date_],[class^=med_group_]')
Hope his helps.
$( $('[id^=med_date_][class^=med_group_]') ).each(function() {
console.log($(this).text());
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id='med_date_1' class='med_group_1'>Span 1</span>
<br>
<span id='med_date_2' class='med_group_2'>Span 2</span>
<br>
<span id='med_date_3' class='med_group_3'>Span 3</span>
You were close. Yes, you can use multiple selectors, you need to remove space as it indicates Descendant Selector (“ancestor descendant”)
$('[id^=med_date_][class^=med_group_]').doSomething()
$('[id^=med_date_][class^=med_group_]').css('color', 'green')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id='med_date_1' class='med_group_1'>Span 1</span>
<br>
<span id='med_date_2' class='med_group_2'>Span 2</span>
<br>
<span id='med_date_3' class='med_group_3'>Span 3</span>
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