Tuesday, 24 September 2019

Javascript how to split newline

I'm use jquery, and I have a textarea, so when I submit button I will alert every text separate by newline. How to split from newline?

  var ks = $('#keywords').val().split("\n");
  (function($){
     $(document).ready(function(){
        $('#data').submit(function(e){
           e.preventDefault();
           alert(ks[0]);
           $.each(ks, function(k){
              alert(k);
           });
        });
     });
  })(jQuery);

example input :

Hello
There

Result I want is :

alert(Hello); and
alert(There)


from Javascript how to split newline

No comments:

Post a Comment