Today i was writing some JavaScript and I wanted to see what was the value of a div id tag element, for example, I had this:

<div id="MyDiv"></div>

So I want to get the actual MyDiv, so in my JavaScript code I had this:

alert(this);

Then I got the pop up message with [object HTMLDivElement]

But I wanted MyDiv to show up.

In order to display MyDiv I had to tell JavaScript what part of the object I need. so it was easy, all I had to do is put a .id next to this. so my code now looks like this:

alert(this.id);
Output: MyDiv