I’m trying to add a custom attribute on my element using jquery :
$('.map-areas-div').rand(numElements).each(function(){
$(this).attr('element_id',4);
});
But in the end, my elements doesn’t have a “element_id” attribute.
PS, my html elements look like :
<div type="ground" class="map-areas-div" style="position: absolute; top: 900px; left: 720px; height: 40px; width: 90px;"></div>
Thank you for help
You can’t. Use jQuery.data api instead to associate custom properties with element’s jQuery wrapper. http://api.jquery.com/jQuery.data/