I have a very simple script that should change links’ ids but somehow it is not working. Here is the code :
$(document).ready( function() {
$('mylinks').each(function(index) {
$(this).attr({
'id': 'mylink-'+index
});
});
});
<div class="mylinks">
<a href="http://www.google.com">google</a>
<a href="http://www.google.com">google2</a>
</div>
I have tries changing mylinks to :
div.mylinksdiv.mylinks a
but none of them worked. What am I missing ?
EDIT
Most of you are right. I have to use $('.mylinks a').each( ... but the issue was that I was looking at the RMB->Source (where the content is not updated) instead of Inspect Element.
Edit your code and change this: