Reputation: 48
I've got some textareas in my page.
<textarea id="first">Some content</textarea>
<textarea id="second"></textarea>
<textarea id="third">other content</textarea>
I would like to get all the textareas with any content i.e. except textareas without any content. In my example, it means first and third textarea.
Upvotes: 1
Views: 43
Reputation: 3640
You can do this,
$(document).ready(function () {
var $elements = $('textarea:not(":empty")');
$elements.each(function () {
var element = $(this);
alert(element.val());
});
});
Upvotes: 0
Reputation: 3966
var $res = $('textarea').filter(function(i, ele){
return $(ele).text() != '';
});
OR
var $res = $('textarea').filter(':not(:empty)');
fiddle: http://jsfiddle.net/qYbvr/ http://jsfiddle.net/qYbvr/1/
Upvotes: 0
Reputation: 128781
Simply combine jQuery's not()
method with its :empty
selector:
$('textarea').not(':empty');
Upvotes: 3