How to get element ID in JavaScript ?
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 | 13591 | alphons | https://en.ans.wiki/766/how-to-get-element-id-in-javascript | 1 |
| 1 | 12445 | en | https://en.ans.wiki/766/how-to-get-element-id-in-javascript | 5 |