<div id="tag<%=count++%>" value="val1">
<div id="tag<%=count++%>" value="val2">
<div id="tag<%=count++%>" value="val3">
Onclick event in jquery need to get value of the div. Exact number of divs created is dynamic
You should use input instead of div:
Try this:
Html :
<input type="text" id="tag<%=count++%>" value="val1"/>
<input type="text" id="tag<%=count++%>" value="val2"/>
<input type="text" id="tag<%=count++%>" value="val3"/>
Jquery:
$( document ).ready(function() {
$('input[id^="tag"]').on('click', function() {
alert(this.value);
});
});
Live demo
using div:
try this:
$( document ).ready(function() {
$('div[id^="tag"]').on('click', function() {
alert($(this).attr('value'));
});
});
demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With