UI practice #2 jQuery - DOM functions and array
Creating boxes with repeating background color - jQuery practice This article gives an idea of jQuery and DOM methods and javascript arrays Many of you have tried our previous practice exercise it seems. Jquery array i) When you get an input, you check whether it is validated as a number, ii) Based on the input value, number of boxes is created. iii) Set all the boxes with background colors from an array How to get an input value from textbox var inputValue = $(this).val(); console.log(inputValue); Testing whether the input value is a number For testing whether it is a number, regex pattern is used. if (/^[0-9]$/.test(inputValue)){ console.log("It is a number"); } /^[0-9]$/ :here,[0-9] checks whether it is a number. Note: /^[0-9]{1,2}$/ refers two digits number Creating number of boxes based on input value var section = document.createElement('section'); for (i=0;i<=inputValue-1;i++){ //crea