I have a .jsp page where many elements have ids that end with a certain string. For example:
<div id="topActions-1083"></div>
<div id="collapse-1083">
<input id="collapse1Input-1083" type="hidden" value="expanded"></input>
</div>
Which is the fastest way to get all elements with id ending in '1083' and change it to '1084' ?
Try this
$("[id*=1083]").each(function(){
var iid = $(this).attr('id')
var fin = iid.replace('1083','1084')
$(this).attr('id',fin)
console.log(fin)
});
Working DEMO
Selectors Example :
Starts with a given string (for example 1083),
$("[id^='1083']")
If you want to select elements which id contains a given string :
$("[id*='1083']")
If you want to select elements which id is not a given string :
$("[id!='1083']")
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