Jump to content

Select Parent Element


Recommended Posts

I am trying to make some modifications to a script. This page has many bullet lists. When you click on the first level bullet it opens the second level and second level opens the third level, you reclick them and they close they're proper level. What I wanna do is when open the + icon in front should be a - icon and then when collapse it should return to a +. Currently it's static, set with css on the li element.Is there a way with JS that I can select the parent element of the item clicked? The link in the bullet is what makes the bullet expan or collapse but I need to add the style to the parent .expan li.

Link to post
Share on other sites

I assume since this is a working script that you already have the element that was clicked sotred in a variable? If so getting the parent is very simple.

var parent = clickedElement.parentNode;

Link to post
Share on other sites

I believe you could just have Javascript later the CSS for the given element. again, clickedElement.parentNode(or if you use mootools, clickedElement.getParent()) would return the parent of the item clicked. you could then say clickedElement.parentNode.style.listStyleType = "etc etc";(if in CSS the element has hyphens in it, you simple joing the words by upper casing the second word. I.E. text-align turns into textAlign)

Link to post
Share on other sites

So I added aspnetguys line and I get this error: Error: clickedElement is not defined.

var parent = clickedElement.parentNode;parent.style.color = red;

Link to post
Share on other sites

do you have the clicked element already stored in a variable? I was working on that assumtion. clickedElements is not a system variabel or anything it is a name I made up. You have to define it.

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...
×
×
  • Create New...