JQuery Live Click Does Not Work in IE with a Label

I have an anchor tag on my page that is added dynamically using jQuery:

<a href="#" id="ClickMe">Click Me</a>

I have the following jQuery within my $(document).ready(function()

$("#ClickMe").live('click', function()
 {
     $("#SomeDiv1").show();
     $("#SomeDiv2").hide();
 });

This works fine in firefox, but not in IE. I am developing in IE8 currently, but I will need it to run in IE7 minimum.

The code probably is working just as it should, only it is not doing what you expect; as you are not doing anything from stopping the click event from causing browser navigation, that might disturb your showing and hiding of divs.

Try the following:

$('#ClickMe').live('click', function(ev) {
    $('#SomeDiv1').show();
    $('#SomeDiv2').hide();

    // Stop event handling in non-IE browsers:
    ev.preventDefault();
    ev.stopPropagation();
    // Stop event handling in IE
    return false;
});
我来评几句
登录后评论

已发表评论数()

相关站点

+订阅
热门文章