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:

Simple Array Sum | Javascript | hackerrank.com

07-05-2020 hackerrank.com javascript arrays array sum

Compare the Triplets | Javascript | hackerrank.com

07-05-2020 hackerrank.com

Get previous date from given date in javascript

06-03-2017 date javascript previous date

How to change background color and color to the text using javascript

27-02-2017 css javascript colors

Sample Validations in javascript

22-02-2017 validations javascript