如果您有以下div:
<div class="container>
<div class="something">some text</div>
</div>
<div class="container>
<div class="something">some text</div>
</div>
<div class="container>
<div class="something">some text</div>
</div>
当你点击类容器时,你怎么能得到类的文本?
答案 0 :(得分:7)
$(".container").click(function(){
var somethingText = $(this).find(".something").text();
});
答案 1 :(得分:1)
$('.container').click(function(){
var something = $('.something', this);
alert(something.text());
});
使用jquery Selector Context http://api.jquery.com/jQuery/