--- title: Onclick Event Attribute --- ## Onclick Event Attribute When the element is clicked fires a event. It works just like the *onclick method* or `addEventListener('click')` to the element. ```html ``` > `event` can be a JavaScript function or you can write raw JavaScript ### Examples Changing the color of a ```

``` element when clicked ```html

Change my color

``` Using raw JavaScript onclick attribute: ```html ``` #### More Information: - [MDN](https://developer.mozilla.org/pt-BR/docs/Web/API/GlobalEventHandlers/onclick)