Reputation: 3699
How to dynamically get each element's innerHTML when accessing by class?
Here is an example: http://jsfiddle.net/DwDsL/
Upvotes: 0
Views: 1824
Reputation: 33618
You might use .each
$('.btnItem').each(function(){
// do your stuff using $(this)
});
Hope this helps
Upvotes: 4
Reputation: 144679
function g() {
$(".btnItem").each(function(){
con = $(this).text();
$("<div>" + con + "</div>").insertAfter(".btnItem")
})
$(".btnItem").remove();
}
Upvotes: 1
Reputation: 20481
$("span.btnItem").each(function(index) {
$("<div>" + $(this).html() + "</div>").insertAfter($(this));
$(this).remove();
});
Upvotes: 1
Reputation: 87073
$('.btnItem').wrap('<div/>');
is enough
if you want to replace <span>
with <div>
remaining its html then try
$('.btnItem').replaceWith(function(a, html) {
return '<div>' + html + '</div>';
});
Upvotes: 1
Reputation: 176896
use each function with class selector and html function to get innerhtml
$('.classname').each(function() {
alert($(this).html());
});
Upvotes: 4