Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

array in javascript

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)

840 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