简体   繁体   中英

How to preserve white spaces and new line in jquery append text

I am submitting textarea using ajax and when I append the response to a class it shows the dummy only when if there is no new line in text area .

HTML

   <p id="updateres_n"></p>
   <div class="update_res"></div>

ajax code

success: function(response){
     document.getElementById('upd_msg').innerHTML="updated";
     $('.update_res').append(response);
  }  

php code

First inserts textarea and print_r new updated text in javascript

<script>
 document.getElementById('updateres_n').innerHTML="<?php print_r (nl2br($updated_text));?>";
</script>

You can achieve it by css, use this and you're done...

.update_res {
    white-space: pre-wrap;
}

also give this css to the textarea also...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM