{"id":5278,"date":"2025-03-04T10:00:45","date_gmt":"2025-03-04T15:00:45","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=5278"},"modified":"2025-03-04T10:00:46","modified_gmt":"2025-03-04T15:00:46","slug":"the-2-5-ways-to-handle-web-events","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/the-2-5-ways-to-handle-web-events\/","title":{"rendered":"The 2.5 Ways to Handle Web Events"},"content":{"rendered":"\n<p>How many ways are there to add an event (like a <code>click<\/code>) to an element? <a href=\"https:\/\/gist.github.com\/WebReflection\/b404c36f46371e3b1173bf5492acc944\">Andrea Giammarchi covers them<\/a>. <\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>&lt;tag onclick \/><\/code><\/li>\n\n\n\n<li><code>tag.onclick = listener<\/code><\/li>\n\n\n\n<li><code>tag.addEventListener('click', listener[, options])<\/code><\/li>\n<\/ol>\n\n\n\n<p>The first two are basically the same (hence the &#8220;2.5&#8221; in the title). I&#8217;d say the vast majority of event handling is through <code>addEventListener<\/code>, but the clearly listed advantages\/disadvantages Andrea goes through are worth understanding. The declarative nature of the first option can be quite handy. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>How many ways are there to add an event (like a click) to an element? Andrea Giammarchi covers them. The first two are basically the same (hence the &#8220;2.5&#8221; in the title). I&#8217;d say the vast majority of event handling is through addEventListener, but the clearly listed advantages\/disadvantages Andrea goes through are worth understanding. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5280,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29],"tags":[75,3],"class_list":["post-5278","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-beat","tag-events","tag-javascript"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2025\/03\/pexels-photo-392018.jpeg?fit=1880%2C1253&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/5278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=5278"}],"version-history":[{"count":1,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/5278\/revisions"}],"predecessor-version":[{"id":5279,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/5278\/revisions\/5279"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/5280"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=5278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=5278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=5278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}