I am developing a web application, I have such a requirement that whenever a user clicks text inside a span , I need to convert it to an input field and on blur I need to convert it back again again. Therefore, I use the following script on one of my jsp pages.
Java Script:
<script type="text/javascript"> function covertSpan(id){ $('#'+id).click(function() { var input = $("<input>", { val: $(this).text(), type: "text" }); $(this).replaceWith(input); input.select(); }); $('input').live('blur', function () { var span=$("<span>", {text:$(this).val()}); $(this).replaceWith(span); }); }
JSP Code:
<span id="loadNumId" onmouseover="javascript:covertSpan(this.id);">5566</span>
Now my problem is that everything works just fine for the first time. I mean, whenever I click on text inside a range for first time , it is converted to an input field, and again onblur it hides back from the input field to plain text. But if you try to do it again, it won’t work. What happened to the above script?
source share