name property in javascript
name property is used to return the name of an specific element.
It can only be used for the following elements, <a>, <applet>, <button>, <form>, <frame>, <iframe>, <img>, <input>, <map>, <meta>, <object>, <param>, <select>, <textarea>.
Syntax
var elem = element.name;
Example Explanation
- In the above example, when the button is clicked fun_name() function is called.
- In the Javascript function, first we are getting the element (document.getElementById("idBtn")) and storing it in attr variable.
- Using the name property, we are getting the name of the button and displaying it (alert (attr.name)).