The attr method of jQuery is used to get the value of the id attribute of a DOM element.
element.attr(attributeName)
attributeName: This is the string value representing the name of the attribute to be retrieved from the DOM element.
This method returns the value of the provided attribute if the DOM element contains this attribute. Otherwise, undefined is returned.
In the "HTML" tab:
div element with an id of test.ele, and assign the created div element as the value.attr method on ele with 'id' as an argument. This will retrieve the id attribute of ele. We will get test, a result that is printed on the console.