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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 239
    Comment on it

    Hello Readers,

    slice() is the jquery method which is used to select the subset part of all the part of the element or it is used to select the element from start to end position having indexing zero. Both start and end are integer value and start parameter is required, while end is optional if we do not use the end parameter then this method search until the end of the set of the elements.

    Syntax :

    $(selector).slice(start,stop)
    

    Parameter :

    start : start is the required parameter which specifies where to start the selection of elements. The index numbers start at 0.

    stop : stop is also a optional parameter which specifies where to end the selection of elements. The index numbers start at 0.

    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").slice(2).css("background-color", "yellow");
    });
    </script>
    </head>
    <body>
    
    <h1>Welcome to My Homepage</h1>
    
    <p>My name is Donald (index 0).</p>
    <p>Donald Duck (index 1).</p>
    <p>I live in Duckburg (index 2).</p>
    <p>My best friend is Mickey (index 3).</p>
    
    <div>Jquery silce method</div>
    
    </body>
    </html>
    

    In the above code we use the slice() method having it's index position 2 (start from zero index) selection of <p> elements from the <p> element with index position 2 in jquery.

 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: