The object does not support this property or method.

As indicated, I get this error on my site. I checked the IE8 developer debugging tool and I have the following code that caused the error.

<!-- slider js code start -->
<script type="text/javascript">
$().ready(function() {
    if(eval(document.getElementById('coda-slider-1')))
    {
        $('#coda-slider-1').codaSlider();
        //jQuery.noConflict(); var $j = jQuery;
    }
}); 

I have included a screenshot from the Chrome debugging tool.

http://img857.imageshack.us/i/javaerror.jpg

http://img204.imageshack.us/i/javaerror2.jpg

Please help me sort it out.

Thank.

+3
source share
3 answers

Try this instead:

$(function() {
    if($('#coda-slider-1').size())
    {
        $('#coda-slider-1').codaSlider();
        //jQuery.noConflict(); var $j = jQuery;
    }
}); 

The source code says: "do not select anything with jQuery and apply a ready-made handler to it." The correct long syntax is:

$(document).ready(function() { ...

Also note that I deleted eval, because it should never be used never, unless this is avoided.

UPDATE

, , jQuery ( , $. script ? , jQuery.noConflict() ?

script , , script coda:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>

2

Kingjiv , , $().ready ( ). , , , jQuery, , , .

+4

, coda-slider-1?

eval, jquery, jquery:

if($("#coda-slider-1").length>0){

}
0

:

  • $().ready . $(document).ready(function $(function.

  • Why use document.getElementById if jQuery already has search elements using selectors in crossbrowsers the way? Just do $("#some").lengthit to see if it exists.

  • Also in your case, I think it’s good to make sure that the method is codaSlider() loaded before the call.

Corrected Code:

$(function() {
    if ($("#coda-slider-1").length > 0 && $("#coda-slider-1").codaSlider) {
        $('#coda-slider-1').codaSlider();
    }
});
0
source

All Articles