0

i have a problem that i cannot solve by myself. Probably is the easier thing but i'm not able to find the problem in this code, so please give me a little help.

I need to do something on a .click event.

Jquery is included and the link works. i have this code in my html file:

<script>
jQuery(document).ready(function() {
jQuery('.contenutotesto').mouseover(function(){$(this).children("img").css( "opacity", "1" );});
jQuery('.contenutotesto').mouseout(function() {$(this).children("img").css( "opacity", "0.7" );});
$( "div" ).live( "click", function() {
  alert( "Goodbye!" );
});
});
</script>

The crazy thing of this code is that the first 2 lines works, all other code will not. I try to put an alert before the 2 mouseover but it did not appear! Firebug does not find errors in console.

Can someone help me? thx. Sorry for my poor english.

2 Answers2

0

Upgrade your jquery and use "on" instead of "live" to bind your event.

<script>
jQuery(document).ready(function() {
jQuery('.contenutotesto').mouseover(function(){$(this).children("img").css( "opacity", "1" );});
jQuery('.contenutotesto').mouseout(function() {$(this).children("img").css( "opacity", "0.7" );});
$( "div" ).on( "click", function() {
 alert( "Goodbye!" );
});
});
</script>
0

Use

$('elem').click(function(){
 alert( "Goodbye!" );
});

or

$(document).delegate('elem', 'click', function(){
  alert( "Goodbye!" );
});

or

$('elem').on('click', function(){
 alert( "Goodbye!" );
});

Do not use .live(), I also don't use it use .delegate() instead.


Jquery live() vs delegate()
Check this out!

Community
  • 1
  • 1