javascript - If returns always true and check each element with has() -


On the input focus, I want to know that there is not a fault class with the msg class, then do something. I tried it with the following code, but if-statement always gives the truth.

jQuery

  $ ('form .field input') .on ('focus blur', function (e) {if ($ (This) .Parent () Find ('.sg') .Parent () No. (': has (.err)')) {$ (This) .Parent () Find ('.sg'). Parent (). Stop () [e.type === 'Focus'? 'SlideDown': 'slideUp'] ();}})   

Then I also use every msg class I want to check that there is also a square of fault with it. And if there is only 1, then I want to select the input in parent.

This is my attempt but it does not work. The parent ('.respect') is ('. Err'). Length === 1) {$ (this) .parents ()

  if ($ ('msg'). . ('Input'). }   

HTML

  & lt; Div class = "field" & gt; & Lt; Input type = "text" & gt; & Lt; Div & gt; & Lt; Div class = "msg" & gt; message. & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "field" & gt; & Lt; Input type = "text" & gt; & Lt; Div & gt; & Lt; div class = "msg err" & gt; AR msg. & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;    

does not return like a boolean, the opposite is the return collection always the truth Is evaluated in the form.

  If ($ (this) .Parent (). ('.sg') Find parent.) (': ((.)')) {  < P> should be:  
  if (! $ (This) .Parent (). Find ('.sg'). Parent () is (': is (er. ')) {// ^ No ^ ^ Boolean Returns    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -