vchris Posted July 19, 2007 Share Posted July 19, 2007 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 More sharing options...
aspnetguy Posted July 19, 2007 Share Posted July 19, 2007 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 More sharing options...
vchris Posted July 19, 2007 Author Share Posted July 19, 2007 Thanks I'll try that when I get a chance. Link to comment Share on other sites More sharing options...
jhecht Posted July 19, 2007 Share Posted July 19, 2007 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 More sharing options...
vchris Posted July 20, 2007 Author Share Posted July 20, 2007 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 More sharing options...
aspnetguy Posted July 20, 2007 Share Posted July 20, 2007 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 More sharing options...
vchris Posted July 20, 2007 Author Share Posted July 20, 2007 I didn't realize clickedElement wasn't a function in JS. Anyway I got it to work thanks a lot Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.