Jump to content
Sign in to follow this  
sajan

How get parent node?

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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"));

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...