jQuery .attr() crashing Internet Explorer

Posted by Sunyatasattva on Stack Overflow See other posts from Stack Overflow or by Sunyatasattva
Published on 2010-04-09T19:52:36Z Indexed on 2010/04/14 0:43 UTC
Read the original article Hit count: 332

Hello everyone,

This is my first time posting a question here, as I usually try to find solutions myself. This one, though, being an IE issue, just drives me crazy.

I use jQuery cycle plug-in on a website I made and, to populate a caption div, I use a little function that is called after the image is loaded, which uses the "alt" attribute of the image. This seems to exasperate Internet Explorer, which, doesn't have the time to fulfill this apparently so-complicated task, and, as the slideshow cycles, it enters in an infinite loop and eventually crashes – the newer the version, the worse the crash: the older IEs just display an error message saying “The webpage cannot be displayed”, while the newer (7 and 8) completely crash the system.

I have no idea on how to solve or work around this. Here is the problematic code.

function changeCaption() {
    var caption = $("img", this).attr("alt");
    $('#caption').fadeIn("slow").html(caption);
}

Thanks in advance for any pointer: I am amazed as how something so simple and globally recognized (didn't encounter any other browser who had problem with this), can cause a problem so big. I also read somewhere that being able to crash a browser remotely is a serious issue :)

Lucio

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-plugins