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:

Check null values in JavaScript?

04-02-2019 JavaScript null check null value

How to insert bulk information into database in single query execution

18-03-2017 insert sql bulk database

How to make an http request in node js

14-03-2017 http module node js

Filters for convert text to camel case in Angular Js

05-03-2017 angularjs camelcase filters

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

27-02-2017 css javascript colors