How to get the object’s name using jQuery ?
In this article, we will learn how to find the name of an element using jQuery. The name attribute can be applied to multiple elements in HTML and is used to specify a name for any element. The name attribute of any element can be found out using the attr() method. This method is used to find the value of any attribute of the first element in the matched set.
As we need to find the name of an element, we will use this method on the required element and pass “name” as the parameter in this method.
// Select the required element let selectedElem = $("elemToSelect"); // Get the name of the element // using thr attr() method let elementName = selectedElem.attr('name'); console.log("The name of this element is:", elementName);
The example below illustrates the above approach:
Example: In this example, we will create a clone of the object using this method.