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:

A Very Big Sum | Javascript | hackerrank

07-05-2020 A Very Big Sum Javascript hackerrank

Check null values in JavaScript?

04-02-2019 JavaScript null check null value

How to search text in string using php ?

29-10-2017 php search string search

How to redirect one page to another page in php

20-03-2017 redirect php

How to find Angular Errors

06-03-2017 errors angularjs exceptionHandler