"=" And equals () and is () methods in js

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.