I want a link like this: When it's clicked, it changes to text, when mouse out of the text, it returns to 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 first time. Seems that $("a").on("click",function(){})
not working after replaceWith
.
fiddle: http://jsfiddle.net/uABC9/4/
I am using jQuery 1.10.1 and tested both FF and Chrome. Please help.