Okay StackOverflow – this is a weird one.
The Problem
So I have a “button” (really just a div with a javascript onclick listener) that gets its text from a database via json on page load. (It makes sense given the application). We are not supporting IE < 9.
The problem is that the text inside the div does not show up in a fresh instance of IE9. HOWEVER, when I open up the developer console (to try to figure out what went wrong) and refresh the page, IE acts as though nothing ever went wrong and populates the button text correctly. It works in every other browser.
What.
The Code
So here’s what I have in PHP:
<div class="dark-button notification-button" data-notification="NOTIF_A">
<span class="float-right">▶</span>
</div>
Javascript (using Jquery 1.8.0):
$('document').ready(refreshNotificationButtons('.notification-button'));
function refreshNotificationButtons(buttons){
var buttons = typeof buttons != 'object' ? $('.notification-button') : buttons;
var allNotifications = {};
var buttonsCount = 0;
buttons.each(function(){
var button = $(this);
if(typeof button.attr('id') == 'undefined') button.attr('id', 'notif-button-' + buttonsCount);
buttonsCount ++;
if(typeof allNotifications[button.attr('data-notification')] == 'undefined'){
allNotifications[button.attr('data-notification')] = [button.attr('id')];
} else {
allNotifications[button.attr('data-notification')].push(button.attr('id'))
}
});
$.get(
'/notifications/get_notifications/' + $.map(allNotifications, function(x, abbr){return abbr}).join(','),
'',
function(data){
$(data).each(function(){
if (typeof allNotifications[this.Notification.NotificationAbbr] != 'undefined'){
console.log(this); //debug
buttonEl = $('#' + allNotifications[this.Notification.NotificationAbbr]);
if(this.Notifications_User.UserID != null) buttonEl.addClass('notification-button-remove');
buttonEl.attr('data-notification-id', this.Notification.Notifications_TableID);
buttonEl.append($('<span class="notification-button-signup-span">' + this.Notification.EnableText + '</span><span class="notification-button-remove-span">' + this.Notification.DisableText + '</span>'));
}
});
},
'json'
);
}
Images
Button before opening dev console:

Button after opening dev console and refreshing:

Conclusion
Any ideas? I’d be happy to post more code if you would like to see it! Thanks in advance.
As commented above,
console.log()doesn’t work so well in IE when there is no console open to write to.You can either remove the calls to
console, or add in this plugin (developed by Paul Irish)http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/