treehouse : what would you like to learn today?
Web Design Web Development iOS Development

can someone tell me what i've done wrong with this following code

  • Hi all, this jQuery code i wrote isn't working, its telling me there is a syntax error on the line with "$(this).animate({" but I don't see it.

    $(document).ready(function(){

    $("#navigation li a").hover({

    $(this).animate({

    border-bottom-left-radius: '0',
    border-top-right-radius: '0',
    border-top-left-radius: '20px',
    border-bottom-right-radius: '20px',

    }, 5000);

    });


    });
  • $(document).ready(function(){
    $("#navigation li a").hover(function() {
    $(this).animate({"border-radius":"20px 0"}, 5000);
    });
    });

    5000 seems like a long time for a hover effect.
  • sadly that doesn't work either :(
  • yes it does, are you loading jqeury? The 5000 puts a 5 second delay on the effect.
  • yes i'm loading jquery, the console keeps telling me theres a syntax error
  • then its in some other part of your script, console.log in firebug to troubleshoot it i guess.
  • I copied and pasted my entire script onto this thread, so what you see is my entire script.
  • This is my test doc and its working here.
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>js border radius</title>
    <style>
    a {background-color:red;}
    </style>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script&gt;
    <script>
    $(document).ready(function(){
    $("#navigation li a").hover(function() {
    $(this).animate({"border-radius":"20px 0"}, 5000);
    });
    });
    </script>
    </head>
    <body>
    <ul id="navigation"><li><a href="#">This is a link</a></li></ul>
    </body>
    </html>
  • In your script I don't think you should have that last comma after the bottom-right radius line
  • @TT_Mark: Was just about to suggest that. That is the problem ;)
  • I should note that the .hover() is made to control both the MouseOver and MouseLeave events. If you're only using it for a MouseOver i suggest using .mouseover()

    $().hover(
    function(){
    // on mouse over code
    },
    function(){
    // on mouse leave code
    });
  • Thanks all,

    I got it working in the end

    @josh, i was planning to add a mouse out event also i just kept it simple to start with to weed out any issues.

    Thanks again all.