Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Demo: <a href="http://jsfiddle.net/QZMP6/23/" rel="nofollow">http://jsfiddle.net/QZMP6/23/</a></p> <p>If you change this:</p> <pre><code> //Make current html content editable $("#"+currentClickedDIV).html("&lt;INPUT id='currentInput' value='"+currentClickedDIVContent+"'&gt;&lt;/INPUT&gt;"); </code></pre> <p>to this:</p> <pre><code> //Make current html content editable $("#"+currentClickedDIV).html("&lt;INPUT id='currentInput' value='"+currentClickedDIVContent+"'&gt;&lt;/INPUT&gt;").children().on('blur', function () { $('#' + currentClickedDIV).off('click').on('click', external_click); }); </code></pre> <p>The event handler will be re-attached after the input element is <code>blur</code>ed. Also notice I moved your code into an external function named <code>external_click</code>. Here is the code from the demo posted above: </p> <pre><code>function external_click() { var currentClickedDIV = this.id; $('#output').append("Clicked: "+currentClickedDIV +"&lt;BR&gt;"); var currentClickedDIVContent = $(this).html(); $('#output').append("HTML: "+currentClickedDIVContent +"&lt;BR&gt;" ); //Make current html content editable $("#"+currentClickedDIV).html("&lt;INPUT id='currentInput' value='"+currentClickedDIVContent+"'&gt;&lt;/INPUT&gt;").children().on('blur', function () { $('#' + currentClickedDIV).off('click').on('click', external_click); }); //Focus cursor on input $("#currentInput").focus(); //On blur replace with plain html, also reenable click? $("#currentInput").blur(function(){ var currInput = $("#currentInput").val(); $("#"+currentClickedDIV).html(currInput ); $('#output').append("New HTML: "+ currInput +"&lt;BR&gt;" ); }); //prevent more triggers within element console.log($(this)); $(this).off("click").on("click", function (e) { e.stopPropagation(); }); return false; } $('.cuboid').on('click', external_click); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload