Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is jquery is() method?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 248
    Comment on it

    Hello Readers,

    is() is the jquery method which is used to checks or matches the selector to selectorElement. It returns a boolean value indicating true or false.

    Syntax :

    $(selector).is(selectorElement,function(index,element))
    

    Parameter :

    selectorElement : It is a required parameter which specifies a selector element to match the current set of elements against selectorElement. It returns true if there is at least one match and false if not.

    function(index,element) : It is a Optional parameter which specifies a function to run for the group of selected elements.

    index - index used for the index position of the element.

    element - element used for the current element.

    Code Example :

    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("p").click(function(){
            if ($("p").parent().is("div")) {
                alert("Parent of p is div"); 
            }
        });
    });
    </script>
    </head>
    <body>
    
    <div>
      <p>Click me</p>
    </div>
    
    </body>
    </html>
    

    In the above code when we click of paragraph p tag we show the alert message if we find out paragraph p tag selector parents is div.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: