Javascript how to split newline
Posted
by
oknoorap
on Stack Overflow
See other posts from Stack Overflow
or by oknoorap
Published on 2011-11-14T17:40:42Z
Indexed on
2011/11/14
17:51 UTC
Read the original article
Hit count: 166
JavaScript
|jQuery
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)
© Stack Overflow or respective owner