frickettz
06-26-2012, 07:05 AM
Hello all,
I'm trying to style a selected state for my nav links but I must be missing something.
Here's my html/css:
<div id="bar_under_brick">
<div class="container-970">
<div class="under_brick_links">
<a onclick="applySelectedTo(this);return false;" href="#" title="">Email Marketing</a>
<a onclick="applySelectedTo(this);return false;" class="selected" href="#" title="">Connect With Us</a>
<a onclick="applySelectedTo(this);return false;" href="#" title="">Ecommerce</a>
</div>
</div>
</div>
And here's the JavaScript I'm using for switching the class for selected state between these links when clicked:
<!-- apply selected state to drop down -->
<script type="text/javascript">
function applySelectedTo(link) {
var ul = document.getElementsByTagName("bar_under_brick")[0];
var allLinks = ul.getElementsByTagName("a");
for (var i=0; i<allLinks.length; i++) {
allLinks[i].className = "";
}
link.className = "selected";
}
</script>
The link that starts out with class="selected" on page load is working fine, but clicking the other links to switch that class does nothing. Am I missing something here?
I'm trying to style a selected state for my nav links but I must be missing something.
Here's my html/css:
<div id="bar_under_brick">
<div class="container-970">
<div class="under_brick_links">
<a onclick="applySelectedTo(this);return false;" href="#" title="">Email Marketing</a>
<a onclick="applySelectedTo(this);return false;" class="selected" href="#" title="">Connect With Us</a>
<a onclick="applySelectedTo(this);return false;" href="#" title="">Ecommerce</a>
</div>
</div>
</div>
And here's the JavaScript I'm using for switching the class for selected state between these links when clicked:
<!-- apply selected state to drop down -->
<script type="text/javascript">
function applySelectedTo(link) {
var ul = document.getElementsByTagName("bar_under_brick")[0];
var allLinks = ul.getElementsByTagName("a");
for (var i=0; i<allLinks.length; i++) {
allLinks[i].className = "";
}
link.className = "selected";
}
</script>
The link that starts out with class="selected" on page load is working fine, but clicking the other links to switch that class does nothing. Am I missing something here?