tags:

views:

97

answers:

2

Hello,

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

+2  A: 

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.

Pointy
Is it not taking function as its second argument?correct me if I am wrong
Jean
@Jean: No, it **takes** a function as second parameter but the **syntax** of your function is **wrong**.
Felix Kling
It is, but what you typed in is NOT a function. It's a syntax error.
Pointy
Can I not use alert pop-up for the above code
Jean
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.
patrick dw
If you don't like alerts (can't blame you) use `$('body').append('test <br />')` instead.
patrick dw
+1  A: 
$(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.

Chacha102