2

I'm encountering quite a weird JavaScript Issue in IE9 (It works fine tough in Chrome, Safari, Firefox).

I have some JS that selects a different Color of an Image when you click on that associated swatch. In IE9, it seems that is completely ignoring this and it is simply doing nothing. But, as soon as I open up the F12 Developer Tools it starts working - Even without reloading the page. Am I mising something here?

jQuery

$('.product-details-description-colors .circle img').click(function() {

  if(!$(this).hasClass('oos')) {

    url = $(this).parent('label').data('image');
    color_value = $(this).parent('label').prev('input');
    color_value.prop('checked', true);

    $('.circle').find('input').not(color_value).attr('checked', false);
    $(this).css('outline', '1px solid black');
    $('.product-details-description-colors .circle img').not(this).css('outline', 'none');
    $('.product-details-images-showroom img').attr('src', url);

  }

});
5
  • 2
    Is this wrapped with the ready event? Are you using console.? Commented Mar 20, 2013 at 0:37
  • 1
    What version of jQuery are you using? And we'd be able to help further if you had some more code, maybe the HTML and CSS? Create a JS fiddle @ jsfiddle.net Commented Mar 20, 2013 at 0:44
  • From my understanding, isn't calling an anonymous jQuery function the same as calling (document).ready? - In addition to that, opening the console or having an output there wont help - As soon as I open the console on IE, it starts working. Commented Mar 20, 2013 at 0:50
  • Even when the developer tools are in a different window? If this is fixed to your screen, see if the issue happens when changing your screen size - as that what the developer tools will be doing. Commented Mar 20, 2013 at 0:58
  • It works, even when the Developer Tools are in a different window - also when I resize the browser, it does not seem to make any changes. I'm completely lost on that issue. Commented Mar 20, 2013 at 1:09

1 Answer 1

3

I assume you haven't posted all your code. One of the most common causes of this is trying to use the console object, specifically console.log. This is only available when the F12 tools are open and if they aren't, it will cause mysterious errors from propagating undefined.

Hence, this is a good idea to put somewhere in your coffeescript app:

# Fix IE logging issues
if not window.console
  window.console = 
    log: ->
Sign up to request clarification or add additional context in comments.

2 Comments

Removing the console.log debugging statements fixed that issue! Thank you!
Run that code above as the page loads and it'll work regardless of whether you remove your statements or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.