jQuery | serialize() with Examples

The serialize() method is an inbuilt method in jQuery which is used to create a text string in standard URL-encoded notation. This method can act on a jQuery object that has selected individual form controls, such as input, textarea etc.

Syntax:

$(selector).serialize()

Parameters: This method does not contain any parameter.



Return Value: This method returns a string of a object for the selected element.

Below example illustrates the serialize() method in jQuery:

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>serialize Method</title>
        <script src=
        </script>
          
        <!-- jQuery code to show the working of this method -->
        <script>
            $(document).ready(function() {
                $("button").click(function() {
                    $("#d").text($("form").serialize());
                });
            });
        </script>
        <style>
            #d1 {
                width: 300px;
                height: 100px;
                padding: 20px;
                border: 2px solid green;
                margin-bottom: 10px;
            }
        </style>
    </head>
    <body>
        <div id="d1">
            <form action="">
                Site Name:
                <input type="text" name="SiteName" value="GeeksforGeeks">
                <br>
                <br> Contributor name:
                <input type="text" name="ContributorName" value="geeks">
                <br>
            </form>
            <!-- click on this button -->
            <button>Click here!</button>
        </div>
        <div id="d"></div>
    </body>
</html>

chevron_right


Output:
serialize method



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.