Creation if -statement in jQuery

How can you say the following in jQuery?

If If textarea AND input.title is NOT empty, then put the input signal.

My attempt in pseudo code

if ( $(textarea).not.empty() AND $(input.title).not.empty() ) {
   $('.ask_question').attr('enabled, 'enabled'); 
}
+3
source share
5 answers

What will jQuery-jesus do?

$('textarea').is(":contains('')")

or

$('input.title').is(":empty")

Suppose;)

+4
source
if ( $("textarea:empty").length == 0 && $("input.title:empty").length == 0 ) {
   $('.ask_question').attr('enabled', 'enabled'); 
}

Property length jQuery returns the number of elements that were selected. : empty is a jQuery selector for selecting elements that 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!
+1
source
if ($("#myTextArea").val().length != 0 AND $("#myTextBox").val() != 0) {
   $('.ask_question').removeAttr("disabled"); 
}

"textarea" "input [ class= 'title']", .

0

.

if ( $("textarea").val().length && $("input.title").val().length ) {
  $('.ask_question').removeAttr('disabled'); 
}
0
if ( $("textarea").val() != "" && $("input.title").val() != "" ) {
   $('.ask_question').attr('enabled', 'enabled'); 
}
-1

Source: https://habr.com/ru/post/1716288/


All Articles