Web pages generate a different number of div blocks with the same id. Blocks
<div id="block"></div> pages can be from one to 5, but no more. To access each block you need to number them. For example:
HTML
<div id="block_1"></div> <div id="block_2"></div> ... How to number id?
JavaScript does it. But, if the blocks are smaller than indicated, setAttribute is empty.
Cannot read property 'setAttribute' of null (...)
for (var i = 1; i < 5; i++) { var el = document.getElementById('block'); el.setAttribute('id', el.getAttribute('id') + i ); }
class- Stanislav Grotif (el) { el.setAttribute(...); } else { break; }if (el) { el.setAttribute(...); } else { break; }- Igorvar el = document.getElementById('block_1');- Viher