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

Detect AdBlock with JavaScript in my browser

30-07-2017 AdBlock javascript detect

How to submit form using javascript or jquery.

16-04-2017 javascript jquery submit form

Sanitization in java sript

14-03-2017 sanitization java script

How to set or update or push the values into Object in javacript

27-02-2017 javascript set update push object