articles

Home / DeveloperSection / Articles / JQuery get method

JQuery get method

Sachindra Singh7469 21-Feb-2011

JQuery get () method is use to get DOM element by selector. In this article I am trying to show you, how we can use get () method on page. In this example I am trying to copy all data of <div> element and want to append in another <div> element as shown below:

Code:
<head runat="server">
<title>JQuery get method</title>
 <script type="text/javascript" src="jquery.min.js">
    </script>
 
    <script type="text/javascript">
 
        $(document).ready(function()        {
            $("button").click(function             {
                $("#div2").text($("#div1").get(0).innerHTML //in this line all text of div1 will copy in div2 and get method that is parametrized is used for to access the element in Nth position
            });
 
        });
    </script>
    <style type="text/css">
        .style1
        {
            width: 163px;
        }
    </style>
</head>
<body>
<h2>JQuery get method</h2>
    <table width="400" cellspacing="5">
        <tr>
            <td align="center">
                <h3>Div element 1.</h3>
            </td>
            <td align="center" class="style1">
                <h3>Div element 2.</h3>
            </td>
        </tr>
        <tr>
            <td align="center">
                <div id="div1">
                   In JQuery, get () method is use to get DOM element by selector. JQuery get ()
                   method is use to get data from server by using Get http request. This is an easy
                   way to send simple request to server. In this article trying to show how we can
                   use get () method.</div>
            </td>
            <td align="center" class="style1">
                <div id="div2">
                </div>
            </td>
        </tr>
        <tr>
            <td align="center" colspan="2">
                <button>
                    Copy data</button>            </td>
        </tr>
    </table>
</body>
Screenshot

JQuery get method

When I will clicked on button data will show on Div element 2 as shown below:

Screenshot

JQuery get method



 


Updated 04-Mar-2020

Leave Comment

Comments

Liked By