lets say inside a <textarea>
, i type in a bunch of keywords on each new line.
keyword1
keyword2
keyword3
...
$('textarea[name=sometextarea]').val().split('\n').each(function(e){
alert($(this));
});
lets say inside a <textarea>
, i type in a bunch of keywords on each new line.
keyword1
keyword2
keyword3
...
$('textarea[name=sometextarea]').val().split('\n').each(function(e){
alert($(this));
});
I think your problem is with the jquery object. val() returns a string and split() will return an Array. But each() is a property of the JQuery object. Try this instead:
$($('textarea[name=sometextarea]').val().split('\n')).each(function(e){
alert($(this));
});
notice the extra $(...) around the the split() return.
The array object doesn't have any each
method. As you are looping strings and not elements, use the jQuery.each
method (instead of the jQuery().each method):
var lines = $('textarea[name=sometextarea]').val().split('\n');
$.each(lines, function(){
alert(this);
});
Like this...
$.each($('textarea[name=sometextarea]').val().split('\n'), function(e){
alert(this);
});
jQuery provides an each
method on the jQuery
(or $
) object. This should be used, rather than creating a jQuery object out of an array:
$.each($('textarea[name=sometextarea]').val().split('\n'), function(e){
alert(this);
});