Created
October 23, 2014 03:14
-
-
Save Deathnerd/dd2918fee9d51202c23d to your computer and use it in GitHub Desktop.
soemthing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head lang="en"> | |
| <meta charset="UTF-8"> | |
| <title></title> | |
| <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script> | |
| <script> | |
| window.number_of_divs = 1; | |
| window.number_of_checked = 0; | |
| window.numbers = []; | |
| window.number_div_skelly = '<div class="number_div"><input type="text" placeholder="Enter a number here"/><input type="checkbox"/><button class="input_button">Click me!</button></div>'; | |
| $(document).ready(function(){ | |
| $(document).on({ | |
| click: function(obj){ | |
| var inputs = $(this).siblings('input'); | |
| var number = $(inputs[0]).val(); | |
| var checked = $(inputs[0]).attr('checked'); | |
| window.numbers.push(number); | |
| window.number_of_checked += (checked) ? 1 : 0; | |
| $('body').append(window.number_div_skelly); | |
| updateValues(); | |
| } | |
| }, '.input_button'); | |
| var updateValues = function(){ | |
| $("#number_of_divs").val(window.number_of_divs); | |
| $("#number_of_checked").val(window.number_of_checked); | |
| $("#sum_of_numbers").val(window.numbers.reduce(function(a,b){return a+b;})); | |
| $("#numbers").empty(); | |
| window.numbers.reduce(function(a){ | |
| $("#numbers").append("<li class='number'>"+a+"</li>"); | |
| }); | |
| } | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <p id="number_of_divs">1</p> | |
| <p id="number_of_checked">0</p> | |
| <p id="sum_of_numbers">0</p> | |
| <ul id="numbers"> | |
| </ul> | |
| <div class="number_div"> | |
| <input type="text" placeholder="Enter a number here"/> | |
| <input type="checkbox"/> | |
| <button class="input_button">Click me!</button> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment