In javaScript or jQuery, the string comparison does not have the equals () method. You can use or is () to determine whether two strings are equal. There is no equals () method for string comparison in javaScript or jQuery. To compare the two strings, you can use = or is () to determine whether they are equal.
For example:
"A" = ""
$ ("# A"). val (). is ("")
Of course, we can write an equals () method by ourselves:
For example:
Js Code
String.prototype.equals = function(s){ return this == s; }
Js Code
function equals(str1, str2) { if(str1 == str2) { return true; } return false; }
Is (expr)
Use an expression to check the selected element set. If at least one element matches the given expression, true is returned.
If no element matches, or the expression is invalid, 'false'. 'filter' is actually called internally. Therefore, the original rules of the filter () function are also applicable here.
Checks the current selection against an expression and returns true, if at least one element of the selection fits the given expression.
If no element fits, or the expression is not valid, then the response will be 'false'. 'filter' is used internally, therefore all rules that apply there apply here, as well.
Return Value
Boolean
Parameters
Expr (String): the filter expression.
Example
Returns true because the parent element of an input element is a form element.
HTML code:
Html code
JQuery code:
Js Code
$("input[type='checkbox']").parent().is("form")
Result:
True
Js Code