• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 54
  • Last Modified:

array in javascript

how to fill multiple values in javascript on each button click
0
pamela rizk
Asked:
pamela rizk
  • 2
  • 2
1 Solution
 
ste5anSenior DeveloperCommented:
Please post a concise and complete example. And give us more context.

$("#target").click(function() {
  var numbers = [1, 2, 3]; 
});

Open in new window

0
 
pamela rizkDeveloperAuthor Commented:
no I want upon clicking the first time to add in the array value 1,
then upon clicking the second time the array should contain value 1 and 2 etc....
0
 
ste5anSenior DeveloperCommented:
E.g.

<!-- saved from url=(0016)http://localhost -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<script src="jquery-2.1.1.min.js" type="text/javascript"></script>
		<script>
			$(document).ready(function() {
				var numbers = []; 
				$("#target").click(function() {
					numbers.push(numbers.length);
					$("#output").text(numbers);
				});
			});
		</script>
	</head>
	<body>
		<div id="target">CLICK</div>
		<div id="output"></div>
	</body>
</html>

Open in new window


Please include such vital information in your first post.
0
 
pamela rizkDeveloperAuthor Commented:
k
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now