I am trying to write a single function to change the text color that works on all p tags. If I have three p tags with different IDs, how would I write a function to get the ID from the element based on which one is clicked? I figure I need to set a variable to be equal to the ID of the element that was clicked, which is what I am struggling with. If there is an easier way I'd sure be open to that as well. Thank you very much for any help.
function changeColor() {
var selected = document.getElementById('first');
selected.style.color = 'red';
}
<p id="first" onclick="changeColor()"> First paragraph.</p>
<p id="second" onclick="changeColor()"> Second paragraph.</p>
<p id="third" onclick="changeColor()"> Third paragraph.</p>