Ofeargall
Ofeargall

Reputation: 5670

preventDefault() and return false; not working on some jCarousellite <a> elements

I'm experiencing a bizarre and frustrating scenario and I can't seem to track it's origin.

On the page I have jCarousellite scrolling a number <li> items. The list is generated from a query and then output to the page with a loop. Inside the list items everything is wrapped in an <a></a> tag.

The carousel works like it should. Right now I only have 2 items returned with the query and they scroll past with no problem.

Strangely, when the first item in the list cycles back through it disregards the preventDefault() or return false and clicks through to the page in the href. Even more strange, it only happens on the first click. When you click the back button and return to the page and click it again it acts as expected meaning, nothing happens until, of course, it cycles back through anew.

Where is the ghost in this machine? I'm not getting any errors in firebug...

Here's the code...

<div id="scroller">
    <div class="slideshow">
      <ul>
        <cfloop query="qScrollers">
          <li>
            <cfset ref = "product.cfm?pid=" & #qScrollers.link#>
            <cfoutput><a href="#ref#" class="specials" title="#qScrollers.title#" ></cfoutput>
            <p><cfoutput>#qScrollers.line1#</cfoutput></p>
            <h1><cfoutput>#qScrollers.line2#</cfoutput></h1>
            <p><cfoutput>#qScrollers.line3#</cfoutput></p>
            <h2><cfoutput>#qScrollers.line4#</cfoutput></h2>
            </a> </li>
        </cfloop>
      </ul>
    </div>
  </div>

And, here's the code that lives inside my $(document).ready() function

    $('.slideshow ul li a').click(function(e){
        e.preventDefault();
    });

//I've tried this too...//
/*$('.slideshow ul li a').click(function(){
return false;
    });*/

$(function() {  
        $(".slideshow").jCarouselLite({  
            vertical: false,  
            visible: 1,  
            auto:2500,  
            speed:400,
            hoverPause:true
        });  
    });

Upvotes: 0

Views: 591

Answers (1)

stealthyninja
stealthyninja

Reputation: 10371

@Ofeargall: Try --

$(function() {  
    $(".slideshow").jCarouselLite({  
        vertical: false,  
        visible: 1,  
        auto:2500,  
        speed:400,
        hoverPause:true
    }); 

    $('a.specials').click(function(e) {
        e.preventDefault();
    });
});

Upvotes: 1

Related Questions