access the value of a div within a li element

2

I have this line

 <li id="liPryName"> <span><i class="glyphicon glyphicon-folder-open"></i></span> <div class="id">Valor de Id</div></li>

I would like with jquery to be able to access the value of class="id" by clicking on the id="liPryName"

I've tried this, but it does not give the result I want. Within <Li> I need to find the value of class="id".

$("#liPryName").dblclick(function () { 
        alert($(this).html());
    })
    
asked by Lorenzo Martín 18.12.2018 в 19:03
source

2 answers

2

You can achieve what you want with .find() like this:

$("#liPryName").dblclick(function () { 
        alert($(this).find(".id").html());
    })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 
 <li id="liPryName"> <span><i class="glyphicon glyphicon-folder-open"></i></span> <div class="id">Valor de Id</div></li>
    
answered by 18.12.2018 / 19:09
source
0

You can do it with children :

$("#liPryName").dblclick(function() {
  alert($(this).children("div").text());
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<li id="liPryName">
  <span>
<i class="glyphicon glyphicon-folder-open"></i>
</span>
  <div class="id">Valor de Id</div>
</li>
    
answered by 18.12.2018 в 19:11