3

As titled, I'm getting this error on my site. I have checked through the IE8 developer debugging tool, and I have got 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 the screenshoot from Chrome debugging tool.

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

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

Please help me to figure it out.

Thank you.

Jone
  • 53
  • 1
  • 1
  • 4

3 Answers3

4

Try this instead:

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

Your original code says "select nothing with jQuery, and apply this ready handler to it." The correct long-hand syntax would be:

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

Also note that I have removed eval because it should never, ever be used, unless it can't possibly be avoided.

UPDATE

Looking at your error screenshots, it appears that jQuery is not defined (at least not with the $ alias. Have you included the script on your page? If so, are you calling jQuery.noConflict() before your ready handler is bound?

Try putting this script tag above both the code you posted, and the script tag for the coda slider:

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

UPDATE 2

As pointed out by kingjiv in the comments below, I was mistaken, and $().ready will work (though it is not recommended). I believe my first update, noting that jQuery appears not to be defined, is the actual issue here.

Ender
  • 14,995
  • 8
  • 36
  • 51
  • 1
    I don't mean to complain, but I've now been downvoted twice with no explanation. I don't mind if you think I'm wrong, but I'd appreciate knowing what the problem is. – Ender May 09 '11 at 17:09
  • Ender, do you mind to help me to fix this issue? I really have no idea on what to do, as I'm not familiar with coding. Would you mind to leave your email so that I could contact you? I do appreciate a lot if you could help me. Thank you in advance. – Jone May 09 '11 at 17:14
  • 1
    @Jone - Sorry, but I'm not going to post my email address in a public space like this. Try following the suggestions I've made. – Ender May 09 '11 at 17:18
  • Ender, I have followed your twitter, please follow me too, so that I can send messages to you. Thanks. – Jone May 09 '11 at 17:19
  • Again, sorry but no. What is wrong with using this comment thread? – Ender May 09 '11 at 17:20
  • I have no idea on those coding stuff, I would like to hire someone to help me, if you can offer me some time to help, I would appreciate it a lot. – Jone May 09 '11 at 17:22
  • I have sent an email to you (m**d*****l*@gmail.com) , Please have a check. Thank you. – Jone May 09 '11 at 17:31
  • My guess is the downvotes are because `$().ready(handler)` is valid, just not recommended. http://api.jquery.com/ready/ – James Montagne May 09 '11 at 17:33
0

I'm guessing you're trying to check for the existence of coda-slider-1?

No need to use eval, and if you're using jquery, may as well select the element with jquery:

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

}
James Montagne
  • 77,516
  • 14
  • 110
  • 130
0

Problems:

  • $().ready isn't recommended. Use $(document).ready(function or simple $(function.

  • Why using document.getElementById if jQuery already lookup elements using selectors in a crossbrowser way? Just do $("#some").length to see if it exists.

  • Also in your case I think is good to ensure that the codaSlider() method is loaded before calling.

Correted code:

$(function() {
    if ($("#coda-slider-1").length > 0 && $("#coda-slider-1").codaSlider) {
        $('#coda-slider-1').codaSlider();
    }
});
Erick Petrucelli
  • 14,386
  • 8
  • 64
  • 84