Forum Moderators: open

Message Too Old, No Replies

addClass Takes Two Clicks To Function

addClass Two Clicks

         

gdogs

12:27 am on Jan 27, 2010 (gmt 0)

10+ Year Member



I'm using "Coda-Slider 2.0" for a tab-based interface. I used external triggers to switch between tabs, and I'm having trouble adding my "selected" class when I click on one of the triggers.

It works...BUT...it takes two clicks for it to respond correctly. The slider works just fine, but the "selected" class isn't added until I click on one of the menu items twice. Here is the JavaScript I used:

$("a").click(function(){
$(".menu a.selected").removeClass("selected"); // remove previous class if there is any
$(this).addClass("selected"); // add class to the clicked link
return false; // this prevents browser from following clicked link
});

And here is the HTML:

<ul class="menu">
<li class="day1"><a class="selected xtrig" href="#1" rel="coda-slider-1">Day 1</a></li>
<li class="day2"><a class="xtrig" href="#2" rel="coda-slider-1">Day 2</a></li>
<li class="day3"><a class="xtrig" href="#3" rel="coda-slider-1">Day 3</a></li>
<li class="day4"><a class="xtrig" href="#4" rel="coda-slider-1">Day 4</a></li>
</ul>
</div

whoisgregg

9:51 pm on Feb 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, gdogs!

Sorry for the delayed response. I would alert(this) to see what it's actually referring to each time you click. That context might be relevant.

Also, what library are you using? jQuery or Prototype?