Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use prepend() method in jQuery ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 155
    Comment on it

    Welcome to findnerd, today we are going to discuss on prepend() method in jQuery.
    Firstly let know what use of prepend() method ?


    prepend() method is used for inserting at the beginning of the selected elements in jQuery

    you can see bellow example how it works

    <!DOCTYPE html>
    <html>
    <head>
         <!--  here call the jquery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("#btn").click(function(){
            $("p").prepend("Fine Joe ");// call prepend() to add text
        });
    });
    </script>
    </head>
    <body>
      <!--  here write paragraf in which you want add text-->
    <p>What about you ?</p>
     <!--define  button id -->
    <button id="btn">Submit</button>
    
    </body>
    </html>
    

    output will be following:

    when you will click on submit button then "Fine Joe " will be add in your beginning of paragraph.

    Fine Joe What about you ?

 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: