I have an empty div <div id="content"></div>
to which I add content via jquery append.
$('#content').append('<div class="sub">sub1</div>');
$('#content').append('<div class="sub">sub2</div>');
$('#content').append('<div class="sub">sub3</div>');
When I click a button I want to run a jquery that reads the content of each sub, but I get nothing, I think because the div elements were added via javascript, so they're not really on the page.
$('.sub').each(function(){
alert($(this).text());
}
How can I still operate on html added via javascript?
对于类,它是$('.sub')
而不是$('sub')
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.