title: Changing list item color on click using Java Script
body: <p>Since I'm new in Java Script, I need to know how can I change list item color or style using Java Script?</p>
  
  <p>For example I have following unordered list in my HTML file:</p>
  
  <pre><code>&lt;ul id="list"&gt;
     &lt;li&gt;Text1&lt;/li&gt;
     &lt;li&gt;Text2&lt;/li&gt;
     &lt;li&gt;Text3&lt;/li&gt;
     &lt;li&gt;Text4&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Now when I click on item it should change the color and when clicking next item it will keep the new color of the previous item and change also color of the newly clicked item (example screenshot below):</p>
  
  <p><a href="https://i.stack.imgur.com/kN1xH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kN1xH.png" alt="Screenshot"></a></p>