Skip to content Skip to sidebar Skip to footer

Click Event Does Not Fire Default Action

So, I have this
    with some events attached with the help of jQuery (1.4.2). All is done in the $(document).ready()-call. The weird thing is that the click on the

    Solution 1:

    This is normal, manually firing a click on an anchor does not follow the link, firing the "default event" is often not the case when simulating the action. Setting the location.href is the way to go here, like this:

    $('.news li').click(function () {
        window.location.href = $(this).find('h3 a').attr('href');
    }).hover(function () {
        $(this).toggleClass('hover');
    }).find('h3 a').click(function (e) {
        e.stopPropagation(); //so ctrl+click works on the link, etc
    });
    

    As an aside, there's no need for the .eq(0), .attr('href') will get the href from the first element in the matched set.

Post a Comment for "Click Event Does Not Fire Default Action"