documentSelectors.html 983 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <script>
  2. /**
  3. * Select various elements on the page for later use
  4. */
  5. // IDs we'll attach to cells
  6. const codeCellId = index => `codecell${index}`
  7. const inputCellId = index => `inputcell${index}`
  8. pageElements = {}
  9. // All code cells
  10. findCodeCells = function() {
  11. var codeCells = document.querySelectorAll('div.c-textbook__content > div.highlighter-rouge > div.highlight > pre, div.input_area pre, div.text_cell_render div.highlight pre')
  12. pageElements['codeCells'] = codeCells;
  13. codeCells.forEach((codeCell, index) => {
  14. const id = codeCellId(index)
  15. codeCell.setAttribute('id', id)
  16. })
  17. };
  18. initFunction(findCodeCells);
  19. // All cells in general
  20. findInputCells = function() {
  21. var inputCells = document.querySelectorAll('div.jb_cell')
  22. pageElements['inputCells'] = inputCells;
  23. inputCells.forEach((inputCell, index) => {
  24. const id = inputCellId(index)
  25. inputCell.setAttribute('id', id)
  26. })
  27. };
  28. initFunction(findInputCells);
  29. </script>