Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery replace element with textbox

I want to replace a p tag with a textbox using jQuery. What I have tried isn't working.

like image 901
Pavan Avatar asked Apr 02 '26 03:04

Pavan


1 Answers

<p> Some text.. </p>


$('p').dblclick(function(){
    var textArea = $('<textarea />')
    var oldText = $(this).text();

    $(this).replaceWith(textArea);
    textArea.val(oldText);
});​

See example here.

On focusout, you can read the new value (or old) and set it back within a p tag.

See that example here

like image 93
Robin Maben Avatar answered Apr 03 '26 18:04

Robin Maben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!