{"id":1013,"date":"2022-07-18T19:48:30","date_gmt":"2022-07-18T19:48:30","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=1013"},"modified":"2022-07-18T19:48:32","modified_gmt":"2022-07-18T19:48:32","slug":"onclick-event-in-javascript","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/onclick-event-in-javascript\/","title":{"rendered":"Onclick Event In Javascript"},"content":{"rendered":"<p style=\"text-align: center;\"><strong>Onclick Event in Javascript<\/strong><\/p>\n<p>As the name of the event suggests, the event is for some click on some element. For example, there is a button, and we want to do something when the user clicks the button. So, using this particular event, we can determine what should happen when someone clicks some particular element.<\/p>\n<p>Now, let&#8217;s have a look at the below program, where we are trying to do something on the click event.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1728 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/click-event-on-some-element-onclick-attribute.jpg\" alt=\"\" width=\"1180\" height=\"536\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/click-event-on-some-element-onclick-attribute.jpg 1180w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/click-event-on-some-element-onclick-attribute-300x136.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/click-event-on-some-element-onclick-attribute-1024x465.jpg 1024w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/06\/click-event-on-some-element-onclick-attribute-768x349.jpg 768w\" sizes=\"auto, (max-width: 1180px) 100vw, 1180px\" \/><\/p>\n<p>As you can see in the above code, there is a button, with the Onclick attribute, and there is a function that is going to execute when the button is clicked. It is written within the script element.<\/p>\n<p>So, this is pretty straightforward, that when we are clicking the button, we are going to get an alert, saying that You clicked the button. You can make use of the Onclick attribute on some element when you want to react to click on that particular element.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Onclick Event in Javascript As the name of the event suggests, the event is for some click on some element. For example, there is a button, and we want to do something when the user clicks the button. So, using this particular event, we can determine what should happen when someone clicks some particular element. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[14,15],"class_list":{"0":"post-1013","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-javascript-tutorial","7":"tag-javascript","8":"tag-javascript-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/1013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=1013"}],"version-history":[{"count":3,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":2415,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/1013\/revisions\/2415"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}