I want to add ID to each element of class .content, and I want each ID to have integer increase by 1. Example:
.content
Try this:
var number = 1; $(".content").each(function() { this.id = 'content_' + number; number++; });
Note: you could just use vanilla JS to assign the attribute id (no need to use jQuery)
id