JQUERY - Load in form with editor

Asked

Viewed 31 times

0

It is possible to play a text all misaligned and full of spaces to the left, above and below. Let it all align and without spaces?

For example:

    
       texto
texto
texto texto
         texto 

and leave like this, all without spaces and aligned to the left:

texto
texto
texto texto
texto

This is already automatic when pasting in the editor (textarea).

  • Man vc can remove whitespace with the replace(' ', '') function from javascript.. and can add CSS classes to format the content.. it would be nice to post your code, what you have done so far so that I can help you better.

1 answer

1


Using jQuery, it can be like this:

$("textarea#txt1").on('input',function(){
  var txt = $(this).val();
  var txt_novo = txt.replace(/(^|[\n\r])([\t\s])+/g, "$1");
  $(this).val(txt_novo);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="txt1" style="width:350px; height: 250px;"></textarea>

  • That was it, man, that’s good. Thank you

  • a layman’s question, I already use this code in the header of the site <script src="https://code.jquery.com/jquery-3.1.min.js"> but it didn’t work, only with this Cdn that you sent. Because?

  • I can’t make it work locally. I don’t know where to put the code here, I still don’t understand the stackoverflow

  • I’m doing everything exactly the same.

  • some things happened. I could only put the function inside the body, the header will not. And use fckeditor, ai complicated everything. No textarea ta working.

  • Cool! You can try to put inside a $( Document ).ready(Function() {...}); in the header to bind the input after the page has loaded! As for the editor, then you’ll have to check if it doesn’t have some pre-processor copy and paste!

  • put before the closure of the body, strange, only works like this. The fckeditor will be fucked, but thanks.

  • Thanks @Rod! If it was helpful, mark the answer ai as solution! Good studies!

  • how does it do that? rs

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.