-2

What is wrong with this jquery code, the error received on IE is

Message: Expected ';'
Line: 10
Char: 10

All I want is to move the mouse over and have an alter pop-up

<script language="javascript" type="text/javascript">
$(document).ready(function() {

    $('#t').bind('onmouseover',function(){
        target: '#t',
        success: function(){
            alert('test');
            }

    });

});
</script>

<div id="t">testing mouse over</div>

Thanks Dave

5
  • 3
    How about using a JS debugger or at least an editor that offers JS syntax highlighting? Then you know what's wrong. Commented Feb 6, 2010 at 15:39
  • 1
    So often I feel like the answer to, "How do I fix this?" is, "Be a programmer" :-) Commented Feb 6, 2010 at 15:43
  • 3
    @Pointy - I know it's Saturday, but be nice. :o) Commented Feb 6, 2010 at 15:52
  • How about you have a look at the examples here: api.jquery.com/mouseover Commented Feb 6, 2010 at 15:56
  • 1
    Also, a 'success' function is used in the jQuery $.ajax command, but not in event binding. Commented Feb 6, 2010 at 15:57

2 Answers 2

2

It's syntactically incorrect. Your call to "bind" should take a function as its second argument, but you've got the syntax of functions and that of object literals jumbled up. I don't know what you want to do so I can't really say how to correct it.

Here's how you'd do an alert on mouseover:

$('#t').bind('mouseover', function(ev) {
  alert('test');
});

Also note that you leave off the "on" in the event name.

Sign up to request clarification or add additional context in comments.

5 Comments

Is it not taking function as its second argument? correct me if I am wrong
@Jean: No, it takes a function as second parameter but the syntax of your function is wrong.
It is, but what you typed in is NOT a function. It's a syntax error.
Pointy and Felix are right. The 'function' you passed as a parameter is broken. You put it in the right place, but as a function, it simply will not operate. When you refer to target:, I assume you want a reference back to the element with the event. This is done so through $(this). Taking Pointy's example, try alert($(this).attr('id')). It will display the id of the element that received the event.
If you don't like alerts (can't blame you) use $('body').append('test <br />') instead.
1
$(document).ready(function() {
    $('#t').bind('onmouseover',function(){
            alert('test');
     });
});

The target and success code you put into your code is simply invalid. The second argument for the bind function must take a function as an argument, and what you wrote was attempting to pass it an object literal, and not even succeeding at that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.