Wedge
Public area => The Pub => Off-topic => Topic started by: MultiformeIngegno on February 3rd, 2013, 03:30 PM
-
This is my .live() script I need to update because it's deprecated:
http://jsfiddle.net/wtz5f/1/
This is my tentative to use .on() for the same behavior (but nothing happens..):
http://jsfiddle.net/PjQ3N/1/
What's wrong with the latter example? :)
-
Two things
1) You're using the function wrong, it should be (similarly for the mouseleave function)
jQuery(document.body).on("mouseenter", "#ultimecomunicazioni", function() {
jQuery('<span id="ultimecomunicazioni_appear" style="font-weight:normal;margin-left:5px">(<a style="color:grey" href="//google.it">tutte</a>)</span>').appendTo(jQuery(this));
});
2) You're delegating events to an ID, that's pointless since you're only supposed to have one element in the DOM with the same ID. You might as well use bind after document.load
-
I got rid of the second event and now the first one works.
:edit: Beaten to the punch :P
-
Two things
1) You're using the function wrong, it should be (similarly for the mouseleave function)
jQuery(document.body).on("mouseenter", "#ultimecomunicazioni", function() {
jQuery('<span id="ultimecomunicazioni_appear" style="font-weight:normal;margin-left:5px">(<a style="color:grey" href="//google.it">tutte</a>)</span>').appendTo(jQuery(this));
});
Yup, this works now ;)
http://jsfiddle.net/5xS6W/1/2) You're delegating events to an ID, that's pointless since you're only supposed to have one element in the DOM with the same ID. You might as well use bind after document.load
Uhm, anyway the documentation(http://api.jquery.com/bind/) says:
As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document. For earlier versions, the .bind() method is used for attaching an event handler directly to elements.
-
What about this?
$(document).on("mouseenter mouseleave", "#ultimecomunicazioni" , function(e) {
if(e.type === 'mouseenter'){
$(this).append('<span id="ultimecomunicazioni_appear" style="font-weight:normal;margin-left:5px">(<a style="color:grey" href="blahblah/">tutte</a>)</span>');
} else {
$('#ultimecomunicazioni_appear').remove();
}
});
-
This one shouldn't be a problem... Should it?