Make an editable paragraph
I want to create an onclick editable paragraph. I made an editable paragraph, but only one problem is that when I click on the side of the text area it becomes the paragraph which is correct, but the second time we click on the paragraph it does not work. I am very sorry for my English. Thanks for helping me.
JSFIDDLE
HTML:
<p id="about">This is paragraph</p>
SCRIPT:
$(document).ready(function() {
function paraClicked() {
var aboutText = $('#about').html();
var editableText = $('<textarea />').css({'width': '100%', 'font-size': '20px'});
editableText.val(aboutText);
$('#about').replaceWith(editableText);
editableText.focus();
editableText.blur(editableTextBlured);
}
function editableTextBlured() {
var text = $(this).val();
viewavleText = $('<p>');
viewavleText.html(text);
$(this).replaceWith(viewavleText);
$(viewavleText).click(paraClicked);
}
$('#about').click(paraClicked);
});
+3
Krishna kumar yadav
source
to share
2 answers
You didn’t provide an id after you changed it to pragr. Change this line
viewavleText = $('<p>');
For this
viewavleText = $('<p id="about">');
+4
Sherlock
source
to share
Only one small change is required, you need to keep the item ID.
viewavleText = $('<p id="about">');
Demo: http://jsfiddle.net/ddsrjppb/2/
+4
sinisake
source
to share