How to pass the id of an element that triggers an `onclick` event to the event handling function

Viewed 223513

How do I pass the id of an element that triggers an onclick event to the event handling function.

I am doing something like this-

<link onclick="doWithThisElement(id_of_this_element)" />
7 Answers

if click any button, it will be call the function and add classList active class

<label for="natural" id="natural" class="Natural" onclick="showContent(this)">Natural</label>

            <label for="labgrown" id="labgrown" class="Labgrown" onclick="showContent(this)">Labgrown </label>

            <label for="fancyColor" id="fancy" class="Fancy" onclick="showContent(this)">Fancy</label>

<script>
    function showContent(event) {
        $(event).addClass("active");
        console.log(jenil);
    }
    
</script>
Related