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

Example for Conditional Operator in php

16-04-2017 php Conditional Operator example

How to find Angular Errors

06-03-2017 errors angularjs exceptionHandler

Filter for change Date Time format (MM-dd-yyyy HH:mm) in Angular Js

05-03-2017 mm-dd-yyyy HH:MM date formats angular js

How to get drop down value when drop down change using javascript

27-02-2017 onchange events dropdown javascript functions