I'm new to jQuery and am facing now a weird problem. I succeeded to narrow it down to the fact that a mouseenter
event is called twice: once for the containing div (this was my intention) and again for elements within this div (not good). I tried to use return false
and stopPropagation
but it doesn't seem to work.
Here's the code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<!-- JS files (order matters!) -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.js"></script>
<script type="text/javascript">
$(function (){
$(".testDiv").hover(
function(e) /* IN */ {
$(this).data("htmlBackup", $(this).html());
$(this).html("TEST 123");
e.stopPropagation();
return false;
}, function(e) /* OUT */ {
$(this).html($(this).data("htmlBackup"));
e.stopPropagation();
return false;
});
});
</script>
<!-- this one works -->
<div class="testDiv" style="border: solid">ORIG HTML</div>
<br /> <br /> <br />
<!-- this doesn't work -->
<div class="testDiv" style="border: solid"> <p style="border: solid">ORIG HTML</p></div>
</body>
</html>
You can also see it here: http://jsfiddle.net/rFqyP/3/
Any help will be very much appreciated!