views:

106

answers:

4
"Object doesn't support this property or method"

It's this line.

pthumb = $("#pthumb").attr("src");

Does anyone know why?

+1  A: 

Are you ensuring the DOM is ready?

$(document).ready(function(){  

    //wrap your code in document-ready check

    pthumb = $("#pthumb").attr("src");  

});
KP
Well, this is a function that I call.
TIMEX
This is likely it. Always use $(document).ready(), it saves a lot of trouble.edit after seeing the above: are you sure the DOM is ready when the function is called?
Jeff
@alex: So you do already call `$(document).ready()`??? Sorry I don't understand your comment.
KP
+4  A: 

You have a javascript variable called "pthumb" and a DOM element with the id "pthumb", and IE's JS engine could be trying to use the wrong one.

If you have a function also called "pthumb" then IE could also be trying perform this action on the function object.

The last thing to try is to make sure you are using "var" when declaring "pthumb" in the Javascript. i.e.:

var pthumb = $("#pthumb").attr("src");
Donal Boyle
I changed all the variable names and nothing was wrong
TIMEX
@alex, after you changed the names, the error still occurs?
Donal Boyle
correct, you're correct!
TIMEX
Cool, glad I could help. I looked into this in more detail to try and remember what else I learned when I first encountered it. I have updated my answer with the other possibilities. Once again IE's error messages are of very little help!
Donal Boyle
A: 

you could double check the plain javascript method:

var jthumb= document.getElementById('pthumb').attributes['src'].value;
try{
pthumb = $("#pthumb").attr("src");
}
catch(er){
alert(er.message + '\n'+jthumb)
}

If you don't catch the error, the element is not yet ready.

kennebec
A: 

And always it's good if you are checking for Jquery object is null or not.

http://praveenbattula.blogspot.com/2010/01/how-to-check-jquery-object-is-null.html

Rare Solutions