How to get id by using name attribute in javascript

html
id
name
javascript

I want to get id of my element by using name attribute, but there is an simple method in javascript. Here is the HTML 

<input type="text" name="name" id="id">

In javacript,

var ele = document.getElementsByName( 'name' );
var id = ele[0].getAttribute( 'id' );

 

You might also like:

Compare the Triplets | Javascript | hackerrank.com

07-05-2020 hackerrank.com

How to get id by using name attribute in javascript

20-03-2017 html id name javascript

How to get current date and time (yyyy-mm-dd H:i:s) using javascript

09-03-2017 javascript date time

Filter for change Date format (MM-dd-yyyy) in Angular Js

05-03-2017 mm-dd-yyyy date formats angular js

Filter for replace text in Angular Js

05-03-2017 filter replace angular js