Hi there,
Just need a quick bit of DOM navigation advice - In the code below I'm looking to dynamically change the class of the <ul> when the user clicks on the <li> item.
So if the user clicks on the first <li> it'll become onestar, if they click on the second it'll become twostar etc...
As I want to use several of these on the same page, it'd be nice if I could refer to the parentelement (ul) using dom scripting.
So could someone give me a pointer as to how I can set the <ul> element this way?
I was trying this.parentNode.className = x;
but that doesn't seem to work? Do I need to define this. or is it just the last item selected in the DOM?
Many thanks for any nifty code you can provide!
Just need a quick bit of DOM navigation advice - In the code below I'm looking to dynamically change the class of the <ul> when the user clicks on the <li> item.
So if the user clicks on the first <li> it'll become onestar, if they click on the second it'll become twostar etc...
As I want to use several of these on the same page, it'd be nice if I could refer to the parentelement (ul) using dom scripting.
So could someone give me a pointer as to how I can set the <ul> element this way?
I was trying this.parentNode.className = x;
but that doesn't seem to work? Do I need to define this. or is it just the last item selected in the DOM?
Many thanks for any nifty code you can provide!
Code:
<script>
test(x){
}
</script>
<ul class="nostar">
<li><a href="#" onClick="test(1)">One</a></li>
<li><a href="#" onClick="test(2)">Two</a></li>
<li><a href="#" onClick="test(3)">Three</a></li>
<li><a href="#" onClick="test(4)">Four</a></li>
<li><a href="#" onClick="test(5)">Five</a></li>
</ul>