I have many divs in ids:
<div class="nameclass" id="name<?= $id; ?>">
something
</div>
And I want to put css to all, but by id not class:
$('div.nameclass').css(...); // Not this way
$('#name<????>').css(...); // this way
How to do it?
I have many divs in ids:
<div class="nameclass" id="name<?= $id; ?>">
something
</div>
And I want to put css to all, but by id not class:
$('div.nameclass').css(...); // Not this way
$('#name<????>').css(...); // this way
How to do it?
You could use an attribute starts with selector:
$('[id^="name"]').css(...);
And if you need even more fine grained control over the selector you could use regular expressions.
Your selector is a string
, so you can build the string by addition (+):
int id = 5;
$("#name"+ id).css(...);
But if you want to select multiple items, I would suggest doing this by class and not ID as ID's are meant for 1 item, classes are meant for a group of items. You could do:
$(".nameclass").each(function() {
if($(this).attr("id").contains("name")) {
$(this).css(...);
}
});