Welcome to another Jquery tutorial series, Today I am going to write about, how to get element Id using Jquery.This is small piece of code but very useful, even though I am working in Jquery from last couple of years, but still some times I forgot how to get the element Id.
Retrive Jquery Element ID
Some times there is requirement to get the id of clicked element or when check-box option is selected or dynamic elements processing. Know more about jquery .attr(), The .attr() method gets the attribute value for only the first element in the matched set, .attr() method returns undefined for attributes that have not been set. It means if you are trying to get ID attribute and id attribute of an element is not define, at that time you will get the "undefined" value.
Jquery .attr syntax
.attr( attributeName ); e.g. .attr("title"); .attr("id");
Jquery .attr() id Example
In below example there are two button on each button click we are going to retrieve respected button id say buttonA and buttonB.