I have a function I'm using to replace some text output with a button or sold out label accordingly.
jQuery(document).ready(function() {
jQuery('td.register').each(function () {
var text = jQuery(this).text();
var exploded = text.split(',');
console.log(exploded[0]);
console.log(exploded[1]);
if (exploded[0] == 0) {
jQuery(this).html("<font color='red'>SOLD OUT</font>");
} else {
jQuery(this).html("<a class='button' title ='Register for this event' href='" + exploded[1] + "'>Register</a>");
}
})
});
It seems to work fine on most browsers, but the client is complaining in IE9 it's not working. When I test it on my computer, most of the time it works, but sometimes it doesn't, and every time I test it on browsershots.org it doesn't work. It shows up in browsershots.org tests as if the jQuery didn't even run.
As a convention, placing the script element just before the closing body tag makes the script wait for the rest of the document to load before running. We also can make this process faster in jQuery by using the $(document). ready() method. The $(document).
A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.
Definition and Usage. The ready event occurs when the DOM (document object model) has been loaded. Because this event occurs after the document is ready, it is a good place to have all other jQuery events and functions. Like in the example above. The ready() method specifies what happens when a ready event occurs.
ready() and $(window). load() event is that the code included inside onload function will run once the entire page(images, iframes, stylesheets,etc) are loaded whereas the $(document). ready() event fires before all images,iframes etc.
console is not defined in IE9 modify your code like
jQuery(document).ready(function() {
jQuery('td.register').each(function () {
var text = jQuery(this).text();
var exploded = text.split(',');
if(typeof(console)!='undefined'){
console.log(exploded[0]);
console.log(exploded[1]);
}
if (exploded[0] == 0) {
jQuery(this).html("<font color='red'>SOLD OUT</font>");
} else {
jQuery(this).html("<a class='button' title ='Register for this event' href='" + exploded[1] + "'>Register</a>");
}
})
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With