?
Solved

array in javascript

Posted on 2016-09-05
4
Medium Priority
?
39 Views
Last Modified: 2016-09-05
how to fill multiple values in javascript on each button click
0
Comment
Question by:pamela rizk
[X]
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
  • 2
  • 2
4 Comments
 
LVL 35

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 35

Accepted Solution

by:
ste5an earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

649 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