The following Is JQuery's Is () method judgment;
Copy codeThe Code is as follows:
$ (Function (){
$ ("Ul"). click (function (event ){
Var tar = event.tar get;
If (tar. tagName = "STRONG "){
Alert (tar. tagName );
}
});
})
The above is the native JS judgment;
Copy codeThe Code is as follows:
$ (Function (){
$ ("Ul"). click (function (event ){
Var tar = event.tar get;
If ($ (tar). is ("strong ")){
Alert (tar. tagName );
}
});
})
Most of the methods in JQuery return JQuery diagonal. While the Is () method returns a Boolean value;
Differences:
$ (Tar): wraps a tar object into a jquery object. Only in this way can jquery's method be used; $ (tar ). is ("strong"): it Is determined by the is () method;
Use of the is method in jQuery
Is () is used to detect whether there are matching elements.
Explanation in the help document: use an expression to check the selected element set. If at least one element matches the given expression, true is returned.
We certainly know that the above statement is correct, but we can also write this statement.
Alert ($ ("input: checkbox "). is (": checked"); // you can determine whether a checkbox is selected. and so on. we can use: Can checked be used or another one. of course .. search for ":" In the help document. All types can be used for judgment.
For example, $ ("input [name = btnClick]"). is (": button") is used to determine whether the control is a button, etc ..
The rest is your own efforts ..