I have a div block where I am trying to find the name of the input element which was clicked and then update the value using jQuery:
$(document).ready(function(){
$(this).click(function(){
console.log($(this).attr('name'));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<input type="text" name="name1" id="id1">TestData1</input>
<input type="text" name="name2" id="id2">TestData2</input>
</div>
When I try to find the input element which was clicked I get undefined.
I am assuming it may be because I am checking click event on this and then again trying to get the attr name of it, but since it can increase to at least 5 input elements and these are being fetched dynamically, I cannot bind the id/class with click event.
<inputtags are self-closing.. like so<input type="text" name="name1" id="id1" />$(document).on('click','input', function...thisis not what you think it is.