IE7 preventDefault() not working on skip links

Posted by josh on Stack Overflow See other posts from Stack Overflow or by josh
Published on 2012-09-07T20:26:21Z Indexed on 2012/09/07 21:38 UTC
Read the original article Hit count: 127

I currently have skip links that jump to the div ids and was using e.preventDefault() to stop the url from changing when jumping to the element but in IE7 and IE8 it doesn't work at all using e.preventDefault() and if I take it out the url changes to the div the anchor tag contains reference to. Is their any fix or way around this?

Here is the code

$('body').delegate('a.skiplink-accessible-text', 'click', function (e) {
    //e.preventDefault();
    if (!$.browser.msie) {
        e.preventDefault();
    }
    var jumpTo = $(this).attr('href');
    $('body').find(jumpTo).attr('tabindex', - 1).focus();

});

EDIT: heres a little jsbin example for testing purposes http://jsbin.com/welcome/20846/edit

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery