<input type="button" id="1" class="add" value="+" title="Add" onclick="set(this);"/>
function set(obj){
alert(obj.id);
}
The above code is not working.
I need to pass the id attribute of the button in the onclick function. Is there any way I could achieve this.
Your html should be
<input type="button" id="1" class="add" value="+" title="Add" onclick="set(this.id);"/>
and write java script function as
function set(id)
{
alert(id);
}
Your title mentions jQuery, but you're working with a JS solution. If you want to do this with jQuery:
HTML:
<input type="button" id="1" class="add" value="+" title="Add" />
JS:
$("#1").click(function(){alert(this.id);});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.