Question #766   Submitted by Answiki on 10/26/2021 at 08:16:56 PM UTC

How to get element ID in JavaScript ?

Answer   Submitted by Answiki on 10/26/2021 at 08:34:18 PM UTC

The simplest way to get the ID of a given element is to use the attribute .id.


element.id


Here is an example :

var el = document.getElementById('myId');

// Should display myId
console.log (el.id);

The same attribute can be used to define the ID of the element:


element.id = 'newId';



4 events in history
Answer by Answiki on 10/26/2021 at 08:34:18 PM

The simplest way to get the ID of a given element is to use the attribute .id.


element.id


Here is an example :

var el = document.getElementById('myId');

// Should display myId
console.log (el.id);

The same attribute can be used to define the ID of the element:


element.id = 'newId';



Answer by Answiki on 10/26/2021 at 08:21:34 PM

The simplest way to get the ID of a given element is to use the attribute .id.


element.id


Here is an example :

var el = document.getElementById('myId');

// Should display myId
console.log (el.id);

The same attribute can be used to define the ID of the element:


element.id = 'newId';



Question by Answiki 10/26/2021 at 08:17:22 PM
In JavaScript, how to get element ID?
Question by Answiki 10/26/2021 at 08:16:56 PM
How to get element ID in JavaScript ?
# ID Query URL Count

Icons proudly provided by Friconix.