Yes you can just use the .id
property of the dom element, for example:
myDOMElement.id
Or, something like this:
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
alert(inputs[i].id);
}
Yes you can simply say:
function getID(oObject)
{
var id = oObject.id;
alert("This object's ID attribute is set to \"" + id + "\".");
}
Check this out: ID Attribute | id Property
This would work too:
document.getElementsByTagName('p')[0].id
(If element where the 1st paragraph in your document)
Super Easy Way is
$('.CheckBxMSG').each(function () {
var ChkBxMsgId;
ChkBxMsgId = $(this).attr('id');
alert(ChkBxMsgId);
});
Tell me if this helps
In events handler you can get id as follows
function show(btn) {
console.log('Button id:',btn.id);
}
<button id="myButtonId" onclick="show(this)">Click me</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With