index.js 782 B

1234567891011121314151617181920
  1. // Task 6.2
  2. let tags = [
  3. {tag: 'div', class: 'item', style: 'color: red; cursor: pointer;', text: 'subject'},
  4. {tag: 'ul', class: 'list', style: 'cursor: pointer;', text: 'definition'},
  5. {tag: 'section', class: 'gallery', style: 'background: #5363db; cursor: pointer;', text: 'photo'}
  6. ];
  7. for(let i = 0; i < tags.length; i++) {
  8. let tagName = tags[i].tag;
  9. let tagClass = tags[i].class;
  10. let tagStyle = tags[i].style;
  11. let tagText = tags[i].text;
  12. let result = document.createElement(tagName)
  13. result.addEventListener( 'click', function(event) {
  14. event.target.style = `color: green;`;
  15. })
  16. result.classList.add(tagClass);
  17. result.setAttribute('style', tagStyle);
  18. result.innerText = `${tagText}`;
  19. document.body.appendChild(result)
  20. }