kh.tab kh.tab - 6 months ago 26
jQuery Question

Read content of div which contain input hidden jQuery

Hi actually i work on CakePHP project using jQuery and AJAX..

So i have a div wich is repeated in a php loop ..
This is what's the div look like:

<div class="heart">
<input type="hidden" id="id of loop iterate" />
</div>


What i want is each time the div is clicked i get the id of the input hidden..

What i tried :

jQuery('.heart').click(function(){
var input=$(this).html();
alert(input.prop('id'));
});


Please help!!

Answer

You can use this

$(this).find('input[type="hidden"]').attr('id')

Working Demo

jQuery('.heart').click(function() {
  var input = $(this).find('input[type="hidden"]').attr('id')
  alert(input);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="heart">
  <input type="hidden" id="id of loop iterate" />Click Me !!!!!!!!!!
</div>