tags:

views:

680

answers:

3

Hi,

My dom looks like:

<div class="blah">
  <a href=""><img .. ></a>
  <strong>blah blah</strong>
  <a href=""><img /></a>
</div>

How can I get the value of the strong when I know the class is "blah" ?

$(".blah").find("strong") doesn't work?

+7  A: 

Try this:

$(".blah").find("strong").html();

$(".blah").find("strong") will only return the jQuery object, not it's contents.

Pim Jager
+6  A: 
var value = $('.blah strong').html();

Simpler than pim's answer but works in manly the same way. It finds all descendants of .blah that are strong tags and gives back the html content of the first one.

Annan
Except it has a typo: $('.blah strong').html();
thenduks
I went for the original selector because the OP might be doing something to .blah before looking for the strong. Something like: $('.blah').doSomething().find('strong').html()
Pim Jager
..continued.. otherwise your selector is more simple.
Pim Jager
A: 

Try this

<script type="text/javascript">
    $(document).ready(function() {
        alert($(".blah > strong").text());
    });
</script>

    <div class="blah">
    <a href="#">
        <img src="#" /></a> <strong>blah blah</strong>
   </div>
The_Lorax