I need a link: When it clicks, it will change the text, when the mouse leaves the text, it will return to the link.
HTML:
<a href="#">click me and change to text</a>
JS:
$("a").on('click',function(){ var $lnk = $(this); var $replace = $('<span>'); $replace.text($lnk.text()); // Link to Text $lnk.replaceWith($replace); // Text to Link $replace.one('mouseout',function(){ $replace.replaceWith($lnk); }); return false; });
The code only works for the first time. It seems that $("a").on("click",function(){}) does not work after replaceWith .
script: http://jsfiddle.net/uABC9/4/
I am using jQuery 1.10.1 and have tested both FF and Chrome. Please, help.
jquery
andyf
source share