Jump to content

Select Parent Element


vchris

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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...