I have HTML code like this:
<div class="a">html value 1</div>
<div class="a">html value 2</div>
How can I access html value 1
and html value 2
using jquery?
I have HTML code like this:
<div class="a">html value 1</div>
<div class="a">html value 2</div>
How can I access html value 1
and html value 2
using jquery?
$('.a')[0].innerHTML;
$('.a')[1].innerHTML;
Separately:
$('div.a:eq(0)').html(); // $('div.a:eq(0)').text();
$('div.a:eq(1)').html(); // $('div.a:eq(1)').text();
Using 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 )
});
$('.a')[0].innerHTML;
$('.a')[1].innerHTML;
Try this:
var a = document.getElementsByClassName('a');
for (var i = 0; i < a.length; i++) {
alert(a[i].innerHTML)
}
© 2022 - 2024 — McMap. All rights reserved.