[object HTMLDivElement] Get Value Of Element ID Instead
- Forums
- Javascipt
- [object HTMLDivElement] Get Value Of Element ID Instead
this page will show you how get value of element id instead of the value of [object htmldivelement] when you try to see what the actual name is in your javascript variable [2239], Last Updated: Mon Jun 24, 2024
Robb
Fri Jan 06, 2012
6 Comments
12240 Visits
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