I have some jQuery code, where you click on text and it changes into an input and when it blurs (looses focus) it changes back to text and visa versa, however on the third call is completely breaks and I have no idea why?
Does someone have any idea?
Code at http://jsfiddle.net/Pezmc/x2fQP/4/
Copy
$(document).ready(function() {
function editfield() { //Handles swapping to textbox
var element = $(this);
alert(element.text());
element.css('cursor', 'auto');
element.css('display', 'inline-block');
element.html('<input type="text" size="25" value="' + element.text() + '" style="width:' + element.width() + 'px;height:' + element.height() + 'px;border:none;padding:0px;margin:0px;">');
element.children('input').focus();
$(element).delegate("input", "focus", function() {
$(element).delegate("input", "blur", function() {
element.html(element.children('input:text').val());
element.css('cursor', 'pointer');
element.one("click", editfield);
});
});
}
////////////////////////////////
$(".field").css('cursor', 'pointer');
$(".field").one("click", editfield);
});