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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 235
    Comment on it

    Hello Readers,

    has() is the jquery method which is used to return the new jquery elements or objects that have one or more elements inside of a subset of the matched elements or matches the given selector in jquery.

    Syntax :

    $(selector).has(element)

    Parameter :

    element : element is the required parameter which specifies a selector expression or an element to match the elements against selector.

    If we use multiple elements inside has() method than we use comma as a seprator.

    For Example :

    $(selector).has(element1,element2)
    

    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").has("span").css("background-color", "yellow");
    });
    </script>
    </head>
    <body>
    
    <h1>Welcome to My Homepage</h1>
    
    <p>My <span>name</span> is Donald.</p>
    <p>I live in <span>Duckburg</span>.</p>
    <p>My best friend is Mickey.</p>
    
    </body>
    </html>
    

    In the above code selector is p tag and element is span,so change its background color yellow of paragraph and its span element content.

 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: