JavaScript for WordPress › Forums › Vanilla JavaScript › 1.4.6 – Event Propagation – Simple question about .id › Reply To: 1.4.6 – Event Propagation – Simple question about .id
May 17, 2017 at 5:50 pm
#27575
Zac Gordon
Keymaster
Actually,
this.id
is shorthand for
this.getAttribute( 'id' )
documentGetElementById( ‘X’ ) will select an element on the page with an ID assigned of ‘X’. Once you get that value, .id would give you the value X.
So something like this:
var el = document.getElementById( 'content' );
console.log( el.id ); // Prints 'content'
Hope that helps! Good question 🙂