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));
});
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);
});
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With