5

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?

fabrik
  • 14,094
  • 8
  • 55
  • 71
mrblah
  • 99,669
  • 140
  • 310
  • 420
  • FYI. The use of inline font styling, while not deprecated, is discouraged in the HTML spec. A better way to handle this would be with a span with a CSS class assigned that styles the element the way you want. – tvanfosson Mar 22 '09 at 15:26
  • 1
    the tag is not inline styling. the tag however is. Please see this: http://stackoverflow.com/questions/271743/whats-the-difference-between-b-and-strong-i-and-em – Pim Jager Mar 22 '09 at 15:29

3 Answers3

15

Try this:

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

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

Pim Jager
  • 31,965
  • 17
  • 72
  • 98
9
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.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
AnnanFay
  • 9,573
  • 15
  • 63
  • 86
1

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>
Simeon Wislang
  • 461
  • 2
  • 9
  • 21