JQuery get method

JQuery get method

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:

<headrunat="server">

<title>JQuery get method</title>

<scripttype="text/javascript"src="jquery.min.js">

</script>

<scripttype="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>

<styletype="text/css">

.style1

{

width: 163px;

}

</style>

</head>

<body>

<h2>JQuery get method</h2>

<tablewidth="400"cellspacing="5">

<tr>

<tdalign="center">

<h3>Div element 1.</h3>

</td>

<tdalign="center"class="style1">

<h3>Div element 2.</h3>

</td>

</tr>

<tr>

<tdalign="center">

<divid="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>

<tdalign="center"class="style1">

<divid="div2">

</div>

</td>

</tr>

<tr>

<tdalign="center"colspan="2">

<button>

Copy data</button></td>

</tr>

</table>

</body>

Screenshot

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