开发者

Selecting text within another div- jquery

If you have the following divs:

<div class="container>
<div class="something">some text</div>

</div>


<div class="container>
<div class="something">some text</div>


</div>


<div cl开发者_StackOverflowass="container>
<div class="something">some text</div>


</div>

When you click on class container, how can you get the text for class something?


$(".container").click(function(){
   var somethingText = $(this).find(".something").text(); 
});


$('.container').click(function(){
  var something = $('.something', this);
  alert(something.text());
});

use jquery Selector Context http://api.jquery.com/jQuery/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜