Reputation:
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(){
//???
});
Upvotes: 1
Views: 48
Reputation: 17944
you can do it like this:
$(".chosen").click(function(){
var cntnt = $(this).html();
});
Note that this returns the content of the FIRST matched element.
Upvotes: 0
Reputation: 30557
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();
});
Upvotes: 1