blah...">

Search for the <strong> tag inside this div tag using jQuery

My house is as follows:

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

How can I get the value of strong when I know that the class is “blah”?

$(".blah").find("strong") does not work?

+3
source share
3 answers

Try the following:

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

$ (". blah"). find ("strong") will return a jQuery object, not the content.

+12
source
var value = $('.blah strong').html();

It's easier than pim to answer, but it works courageously the same. It finds all descendants of .blah, which are strong tags, and returns the html content of the first.

+9
source

try it

<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>
+1
source

Source: https://habr.com/ru/post/1705154/


All Articles