Reputation: 141440
How can you say the following in jQuery?
If If textarea AND input.title are NOT empty, then put input.button ON.
My attempt in pseudo-code
if ( $(textarea).not.empty() AND $(input.title).not.empty() ) {
$('.ask_question').attr('enabled, 'enabled');
}
Upvotes: 2
Views: 7354
Reputation: 251262
if ($("#myTextArea").val().length != 0 && $("#myTextBox").val().length != 0) {
$('.ask_question').removeAttr("disabled");
}
You can use "textarea" and "input[class='title']", but it is possible for these to return multiple results.
Upvotes: 0
Reputation: 2587
if ( $("textarea:empty").length == 0 && $("input.title:empty").length == 0 ) {
$('.ask_question').attr('enabled', 'enabled');
}
The method property length of jQuery returns the number of elements which were selected. :empty is a selector for jQuery to select elements which have no child or no text.
So,
if (number of empty textarea is 0) AND (number of empty input with the class title is 0) then
enable somthing!
Upvotes: 1
Reputation: 6704
What would jQuery-jesus do?
$('textarea').is(":contains('')")
or
$('input.title').is(":empty")
I suppose ;)
Upvotes: 4
Reputation: 31761
Not too far off.
if ( $("textarea").val().length && $("input.title").val().length ) {
$('.ask_question').removeAttr('disabled');
}
Upvotes: 0
Reputation: 1793
if ( $("textarea").val() != "" && $("input.title").val() != "" ) {
$('.ask_question').attr('enabled', 'enabled');
}
Upvotes: -1