Home › Forums › JavaScript › Full Page Background Image | jQuery Problem in IE7 and 8 › Re: Full Page Background Image | jQuery Problem in IE7 and 8
June 28, 2012 at 6:43 pm
#105030
Member
You are re-using ID values on key elements. You should avoid this and use classes instead when you have multiple elements that should share a handler. I see that you’re doing this with #bks specifically, which is the element jQuery tries to manipulate. This will definitely cause problems with jQuery’s access to those elements.
You could avoid using the id values altogether and reduce your code a bit:
$(function() {
$(window).on("resize", function(){
var self = $(this);
$(".slide > img").prop("class", function(){
return self.width() > self.height() ? "bgwidth" : "bgheight" ;
});
}).trigger("resize");
});
I would also encourage you to run your code through a validator and cleanup any errors it reports. I passed your front page through the w3 validator and it turned up 9 errors I believe.