Solved

array in javascript

Posted on 2016-09-05
4
22 Views
Last Modified: 2016-09-05
how to fill multiple values in javascript on each button click
0
Comment
Question by:pamela rizk
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Stefan Hoffmann
Comment Utility
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
 

Author Comment

by:pamela rizk
Comment Utility
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
 
LVL 32

Accepted Solution

by:
Stefan Hoffmann earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:pamela rizk
Comment Utility
k
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now