cheng
cheng

Reputation: 6696

jquery: mouseover works, but click wont' work

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<script src="jquery-1.6.2.js"></script>
<script>
$("#test").live("click", function(){
    alert('');          
});
$("#tbl").live("mouseover",function(){
    $("#title").html('<input id="test" type="button" value="test button" />');
});
$("#tbl").live("mouseleave",function(){
    $("#title").html('');
});

</script>

</head>
<body>
<table id='tbl' width="200" border="1">
  <tr>
    <td id="title">&nbsp;</td>
  </tr>
  <tr>
    <td id="content">&nbsp;</td>
  </tr>
</table>
</body>
</html>

$("#test").live("click"...) doesn't work, but if I change to mouseover it works. Any one can help?

Thanks, Cheng

Upvotes: 0

Views: 1149

Answers (6)

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21376

Use mouseenter instessd of mouseover,and as @davecoulter said put ";" end of the statments,

  $("#test").live("click", function(){
        alert();
    });
    $("#tbl").live("mouseenter",function(){
        $("#title").html('<input id="test" type="button" value="test button" />');
    });
    $("#tbl").live("mouseleave",function(){
        $("#title").html('');
    });

here is the jsfiddle http://jsfiddle.net/Z2ZYs/1/

Upvotes: 1

Gordian Yuan
Gordian Yuan

Reputation: 5070

Try replace alert() to alert("Anything"); It's just work fine on my computer.

Upvotes: 0

ar3
ar3

Reputation: 4073

You just need to put a string in the alert('Something') statement.

I have a working example here (jsFiddle)

Upvotes: 0

John Kalberer
John Kalberer

Reputation: 5800

Your problem is that you are using mouseover instead of mouseenter. I have a working example here.

Upvotes: 0

Kanishka Panamaldeniya
Kanishka Panamaldeniya

Reputation: 17586

the problem is alert() does not work like this . just do this alert('');

Upvotes: 0

davecoulter
davecoulter

Reputation: 1826

Cheng:

Just a stab, but try putting ';' at the ends of your statements:

$("#test").live("click", function(){
    alert();
});
$("#tbl").live("mouseover",function(){
    $("#title").html('<input id="test" type="button" value="test button" />');
});
$("#tbl").live("mouseleave",function(){
    $("#title").html('');
});

Upvotes: 0

Related Questions