[object HTMLDivElement] - Get Value Of Element ID Instead

RegisterLogin
[object HTMLDivElement] - Get Value Of Element ID Instead
Post Description: 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
Tags: javascript,code,computer,programming
This Post Was Posted On Jan 06, 2012 By Robb #4072
06p-4072-object-htmldivelement.jpg border=
so today i was writing some javascript and i wanted to see what was the name of a div id, 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.

so 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);
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
rookie
#9977 1
I passed my div.id to the javascript function and I wrote :alert(this.id) and I received this message
(undefined). I want to retrieve the div.id I passed
Can you help me>
Thanks
Sep 24, 2012 Reply Report abuse
Malik
#9547 2
great tip
dude can you tell me how can i assign a particular div as object in javascript
something like that
var myDiv = object HtmlDivElement
Mar 06, 2012 Reply Report abuse
©2012 Webune Forums - Mon Sep 24, 2012 10:25 pm
Powered by: Webune Forums V3