javascriptjqueryhtmlonclickdom-events

Which HTML tags can be used with onClick event?


Which HTML tags can have an onclick event and which cannot? If there are tags where I cannot include an onclick event I want to know why not?

onclick="func()"

Are there any rules that you should adhere to?


Solution

  • All HTML elements can have an onclick attribute.

    See the HTML 5 specification for confirmation.

    (Of course, some elements are not rendered by default so you would have to alter their display properties with CSS before they can be clicked on to trigger the event handler).