Hello everyone, there was such a question. Is it possible to prevent the user from editing the "html" tags in the form of textarea? for example in textarea by default such code

<div class="fottextb"> <p align="center" class="fottext1">Contact Us</p> <p align="center" class="fottext2">Tel:</p> </div> 

It is necessary that the user can edit plain text but the html tags are not edited. Is it possible?

  • If you don’t need to edit them, why show them? make 3 input fields or use the conenteditable property. - sercxjo
  • the fact is that so you can connect a large code, edit it and paste into a file, and from index.php specify the path to this file. Thereby editing this file. In index.php, the text that comes from this file will automatically change. And without the html code. you have to create a separate content file for each entry. - hovdev

1 answer 1

Use contentEditable for a regular div , and if you need to send data from the textarea , you can copy everything into the textarea , which will have the Hidden property, during the editing process, or before sending.

In this example, everything is immediately copied to textarea with id="code" .

 $('.fottextb').each(function(){ this.contentEditable = true; }); // перемещение кода в textarea $('.fottextb').bind( 'DOMSubtreeModified',function(){ $('#code').html($('.fottextb').html()); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="fottextb"> <p align="center" class="fottext1">Contact Us</p> <p align="center" class="fottext2">Tel:</p> </div> <textarea id="code" hidden></textarea> 

  • Only a user can edit internal tags altogether while editing - sercxjo
  • Could you describe the logic of this script in more detail? It is necessary for me that, html entities in textarea could not edit, but the lines could. Here is another example. <p align = "center" class = "fottext2"> Tel: </ p> It is necessary that the <p> code could not be edited, and the line in it Tel: - could be edited, so I asked if this is possible and Does this make your script? - hovdev