In JavaScript, how to get element ID?
In JavaScript, the simplest way to get the ID of a given element (<div id="monId">) 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';
In JavaScript, the simplest way to get the ID of a given element (<div id="monId">) 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';
In JavaScript, 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';
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';
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';
| # | ID | Query | URL | Count |
|---|---|---|---|---|
| 0 | 13168 | en | https://en.ans.wiki/767/in-javascript-how-to-get-element-id | 7 |