event.preventDefault() or return false don't work in IE9 - by Amrita2

Status : 

  Not Reproducible<br /><br />
		The product team could not reproduce this item with the description and steps provided.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


ID 812247 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 12/23/2013 3:08:23 PM
Access Restriction Public

Description

I'm unable to trigger the onclick trigger via JQuery or using the onclick attribute (unless I have the developer tools on with a debug point added)  in IE9. 
The code works perfectly in previous versions of IE but not in IE9. Haven't tested in IE10. Also works in other browsers.

The code seems to work fine when I use
<a href="javascript:callFunction()">Do something </a> with native Javascript:
function callFunction() {

// Do something

}

However it doesn't work when I use with JQuery, or when I use the functionality to  be called via onclick="callFunction()". 
Example: 
<a href="" onclick="callFunction()">Not working </a>

I need to access the attributes of the event triggering element, like class and custom attributes. JQuery has a very easy way for me to do this  within the .click call
       $('a[href="#"]').click(function(e) {
                e.preventDefault();
                      //IF IE version is 9 or greater
                    // e.returnValue = false;
                    //e.cancelBubble = true;
                    
             var classAttribute = $(this).attr("class"); 

               // Do something with the class attribute

                
            });

$(this).attr("attributeName")
 but native Javascript doesn't. Also, I don't want to hard-code the call within the HTML, but use JQuery's .click technique

Sign in to post a comment.
Posted by Microsoft on 2/28/2014 at 2:06 PM
At this time we will go ahead and close out this feedback as no repro. If you are still able to reproduce the issue will you please reopen this bug and provide information\data previously requested.
Best regards,
The Internet Explorer Team
Posted by Microsoft on 1/31/2014 at 11:21 AM
Hello Amrita2,
Thank you for the feedback. We have been testing the example you provided at http://jsfiddle.net/4hfjq/ with IE 9.0.8112.16421 and we are not able to reproduce the issue. Can you please confirm you still experience the problem with IE 9.0.8112.16421?
Best regards,
The Internet Explorer Team
Posted by Amrita2 on 12/26/2013 at 2:30 PM
Hello,

I don't see any error as such, and there is no console.log. The problem appears to be that when we put in <a href="">Do something</a>
and put the onclick trigger via JQuery it is failing by trying to go to "" link, it does appear to trigger, still the href="" seems to take precedence. This is happening only in IE9.

Example:
<a href="#">X</a>
            $('a[href="#"]').click(function(e) {
                alert('preventDefault always');            
             e.preventDefault();
            }

Here is a code sample, can you please try to see the behavior in IE9: http://jsfiddle.net/4hfjq/
Posted by IECustomizer on 12/23/2013 at 6:51 PM
Hi,
check your scripts for calls to the console object....
eg....
In IE9
console.log will fail and raise an unhandled error unless the developer tools are displayed.

this was corrected in IE10.

check your webpage for common compatibility and coding issues at http://modern.ie

Include the version number of jquery that you are using in your questions. or check at bugs.jquery.com for known issues with the jquery version you are using.