How to get id by using name attribute in javascript

20-03-2017 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:

How to redirect one page to another page in php
20-03-2017 redirect php
Remove last two characters from given string using slice
07-03-2017 slice remove
Filter for change Date format (MM-dd-yyyy HH:mm) in Angular Js
05-03-2017 mm-dd-yyyy HH:MM date formats angular js
Filter for replace text in Angular Js
05-03-2017 filter replace angular js
Get Unique values from array/object in javascript
19-02-2017 javascript unique remove repeated values from array