 <p>The issue is in <code>e.target.Id</code>. It should <code>id</code>(lower case) since <code>javascript</code> is a case-sensitive language.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var list = document.querySelector("ul"); list.onclick = function(e) { if(e.target.tagName === "LI") { e.target.classList.toggle("done"); } }; var list2 = document.getElementById("list2"); list2.onclick = function(e) { if(e.target.id === "text") { e.target.classList.toggle("done"); } };</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>.done{ background-color:greenyellow; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;ul&gt; &lt;li&gt;One&lt;/li&gt; &lt;li&gt;Two&lt;/li&gt; &lt;li&gt;Three&lt;/li&gt; &lt;/ul&gt; &lt;div id="list2"&gt; &lt;p id="text"&gt;Text&lt;/p&gt; &lt;p id="text"&gt;Text&lt;/p&gt; &lt;p id="text"&gt;Text&lt;/p&gt; &lt;/div&gt;</code></pre> </div> </div> </p>