How to get the content of one clicked div on click event?
<div class="chosen">a</div>
<div class="chosen">b</div>
<div class="chosen">c</div>
jQuery
$(".chosen").click(function(){
//???
});
If you only want text
$(".chosen").click(function(){
var content = $(this).text();
});
If you want all contents(HTML elements and text nodes)
$(".chosen").click(function(){
var content = $(this).contents();
});
you can do it like this:
$(".chosen").click(function(){
var cntnt = $(this).html();
});
Note that this returns the content of the FIRST matched element.
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.