Solved

array in javascript

Posted on 2016-09-05
4
31 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 33

Expert Comment

by:ste5an
ID: 41784369
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
ID: 41784484
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 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 41784572
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
ID: 41784642
k
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

815 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