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 |
---|