Introduction:
Ion this article I will explain how to add items into array
by using jQuery. We can add items to array by using push property of jQuery.
Items can be added by using
server side code, but it will decrease the performance of the application.
jQuery is fast, so it will increase the performance of the page.
<script type="text/javascript">
$(function
() {
var arr
= [];
$('#btnInsert').click(function () {
var
str = $('#txtname').val();
arr.push(str);
for
(var i = 0; i < arr.length; i++) {
alert(arr[i])
}
});
})
</script>
Full Source Code: Sample application
to insert item to Array
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery Add Items to Array</title>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function
() {
var arr
= [];
$('#btnInsert').click(function () {
var
str = $('#txtname').val();
arr.push(str);
for
(var i = 0; i < arr.length; i++) {
alert(arr[i])
}
});
})
</script>
</head>
<body>
<center>
<fieldset style="width:300px">
<legend><strong>Push
Method of jquery </strong></legend>
<div>
<br />
Enter
Name: <input
type="text"
id="txtname"/><br /><br />
<input type="button"
id="btnInsert"
value="Insert
Item" />
</div></fieldset></center>
</body>
</html>
0 comments:
Post a Comment