/    Sign up×
Community /Pin to ProfileBookmark

altering class of child elements.

Hi everyone,

I need a little help. I have some ajax that displays an image based on the url of a link. First let me show the html…

[CODE]<ul>
<li><a href=”/portfolio/graphic-design/corporate-identity/ar-marketing-andpr/im73″ title=”ar_01.jpg” onclick=”return folioNav(this);” onkeypress=”return folioNav(this);”><span>ar_01.jpg</span></a></li>
<li><a href=”/portfolio/graphic-design/corporate-identity/ar-marketing-andpr/im74″ title=”ar_02.jpg” onclick=”return folioNav(this);” onkeypress=”return folioNav(this);”><span>ar_02.jpg</span></a></li>
<li><a href=”/portfolio/graphic-design/corporate-identity/ar-marketing-andpr/im75″ title=”ar_03.jpg” onclick=”return folioNav(this);” onkeypress=”return folioNav(this);”><span>ar_03.jpg</span></a></li>
</ul>[/CODE]

now the javscript grabs the url sent and uses some ajax to detect the correct path to the image that is ‘disguised’url in the. That works fine.

What I need is to manipulate the classes of the li elements. SO when a link within that unordered list is clicked, I need to set all the li elements to have no class and then give the parent li of the link clicked a class of ‘live’.

I hope I explained that ok.

ANy help would be very much appreciated.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@RobDavidMar 15.2007 — do you mean something like....

el = (the anchor element that was clicked i.e. this)

activeLI = el.parentNode;

parentUL = activeLI.parentNode;

for(i=0;i<parentUL.childNodes.length;i++){

parentUL.childNode[i].className = "";


}



activeLI.className = "live";
×

Success!

Help @ToonMariner spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...