⊗jsPmPrEA 483 of 504 menu

Element activation in JavaScript

Suppose we have some HTML table #table with empty cells.

Let's make it so that when you click on any cell, it is somehow activated, for example, it gets a red background. To do this, we will add some CSS class to activated cells:

.active { background: red; }

Let's implement activation:

let tds = document.querySelectorAll('#table td'); for (let td of tds) { td.addEventListener('click', function() { this.classList.add('active'); }); }

Given an HTML list ul. Make it so that when you click on any item in the list, it is activated with a red background.

Modify the previous task so that by clicking on the activated list item, activation is removed from it.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline