sajan Posted January 14, 2008 Share Posted January 14, 2008 How can i get the id of parent node of an element? Link to comment Share on other sites More sharing options...
Ingolme Posted January 14, 2008 Share Posted January 14, 2008 object.parentNode.getAttribute("id") should work fine.However, if the parent node doesn't have an ID this isn't going to be much use. If you want to just get the parent node alone just use object.parentNode. Link to comment Share on other sites More sharing options...
sajan Posted January 14, 2008 Author Share Posted January 14, 2008 Can you explain me the above?childnode='testChild';// id of a div How can i get the parent id of childnode? childnode.parentNode.getAttribute(childnode) ; Is it the right way?i am getting errors. Link to comment Share on other sites More sharing options...
Ingolme Posted January 14, 2008 Share Posted January 14, 2008 Because all you're doing is telling the variable "childnode" to be a string that says "testChild".The variable [childNode] is reserved anyways.What you're supposed to do is this://Write the following code as it is into your document.var obj = document.getElementById("testChild");alert(obj.parentNode.getAttribute("id")); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.