Guest User

Untitled

a guest
Aug 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. /* JavaScript function to create the grid when submit button is clicked.
  2. * It takes in height and width of the grid from the html form and creates
  3. * the grid on the table canvas element in html page.
  4. */
  5. function makeGrid() {
  6. var height = document.getElementById('input_height').value;
  7. var width = document.getElementById('input_width').value;
  8. var table = document.getElementById('pixel_canvas');
  9. // Table grid creation code :
  10. table.innerHTML = '';
  11. var tbody = document.createElement('tbody');
  12. for (var i = 0; i < height; i++) {
  13. var tr = document.createElement('tr');
  14. for (var j = 0; j < width; j++) {
  15. var td = document.createElement('td');
  16. td.appendChild(document.createTextNode(''));
  17. tr.appendChild(td);
  18. }
  19. tbody.appendChild(tr);
  20. }
  21. table.appendChild(tbody);
  22. }
  23.  
  24. //jQuery to change color of pixel when clicked.
  25. $('body').on('click', 'td', function() {
  26. var color = document.getElementById('colorPicker').value;
  27. $(this).css('background-color', color);
  28. });
Add Comment
Please, Sign In to add comment