How to get innerHTML for a specific html element through its class in jQuery?
4 answers
Separately:
$('div.a:eq(0)').html(); // $('div.a:eq(0)').text();
$('div.a:eq(1)').html(); // $('div.a:eq(1)').text();
Using a loop:
$('div.a').each(function() {
console.log( $(this).html() ); //or $(this).text();
});
Using .html()
$('div.a').html(function(i, oldHtml) {
console.log( oldHtml )
});
Using .text()
$('div.a').text(function(i, oldtext) {
console.log( oldtext )
});
+6