jQuery - How to get text from div > p

后端 未结 1 1081
别跟我提以往
别跟我提以往 2021-01-27 06:38

How to get the subject name from within a div class?

English

相关标签:
1条回答
  • 2021-01-27 06:50

    $(".subject ").click(function() {
      // the script will declare here.
      alert('You are select ' + $(this).find('p').text() + ' subject ');
    });
    div {
      border:1px solid #999;
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <div class="subject ">
      <img src="image/eng.jpg" />
      <p>English</p>
    </div>
    <div class="subject ">
      <img src="image/bio.jpg" />
      <p>Biology</p>
    </div>
    <div class="subject ">
      <img src="image/math.jpg" />
      <p>Mathematic</p>
    </div>
    <div class="subject ">
      <img src="image/sci.jpg" />
      <p>Science</p>
    </div>

    0 讨论(0)
提交回复
热议问题