To learn more, see our tips on writing great answers. This will work <button id="cookieAccept" class="cookieButton">Accept</button> <script> var acceptButton = document.getElementById("cookieAccept"); acceptButton.onclick = function() { alert("HELLO"); } Try replacing. </p> <script> function myFunction () { I prefer using Ids to add event listener to separate your code from html so I add an Id to your select tag with "my-select" for example and select this tag by its Id and add onchange event listener. Using JavaScript, this event can be dynamically added to any element. Let . How to incorporate characters backstories into campaigns storyline in a way thats meaningful but without making them dominate the plot? The onclick attribute fires on a mouse click on the element. Making statements based on opinion; back them up with references or personal experience. rev2022.11.15.43034. How to call multiple JavaScript functions in onclick event? 505). or something similar. See request time in Chrome developer tools. The onClick () event can be used with <select> tags - however, you probably are looking for functionality where it would . Furthermore, by the look of your <c:.> tags, you are also trying to use JSP syntax in a plain HTML document. How can I attach Harbor Freight blue puck lights to mountain bike for front lights? See the HTML 5 specification for confirmation. loop over multiple items in a list? I think, that he talking about HTML tags, not about element classes or id's. All HTML elements can have an onclick attribute. When the migration is complete, you will access your Teams at stackoverflowteams.com, and they will no longer appear in the left sidebar on stackoverflow.com. yep. a tag onclick event a tag onclick function onclick a how to assign a function to onclick property of button in html btn.onclick = function () <a> onclick onclick for anchor tag html href onclick click html anchor tag click event href onclick event html onclick alert how to get element onclick in javascript i tag onclick <a> onclick html Thanks. How to dare to whistle or to hum in public? if(typeof ez_ad_units!='undefined'){ez_ad_units.push([[300,250],'errorsandanswers_com-box-3','ezslot_0',119,'0','0'])};__ez_fad_position('div-gpt-ad-errorsandanswers_com-box-3-0');How to use onClick() or onSelect() with option tag? Neither the onSelect () nor onClick () events are supported by the <option> tag. The onClick () event can be used with <select> tags - however, you probably are looking for functionality where it would be best to use the onChange () event, not onClick (). Stamp out, eliminate and abolish redundancy! How can a retail investor check whether a cryptocurrency exchange is safe to use? <option> elements go inside a <select> , <optgroup>, or <datalist> element. and its a good idea to use descriptive names that match the program and task you are working on am currently writing a similar program to accept and process postcodes using your code and modifying it with descriptive names the object is to make computer language as close to natural language as possible. is there any chance to do the same thing with AngularJS ng-change event ? How do I create an HTML button that acts like a link? what does onclick do in javascript button on click tell javascript onclick event on a div html menu bar onclick w3schools php echo java onclick function onclick html attribute onclick on a tag a tag on click a tag onclick event onclick show message javascript onclick in a tag html input button onclick can a tag have onclick button onclick html What am I missing here? Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. It supports all HTML elements except . 'Duplicate Value Error'. Asking for help, clarification, or responding to other answers. Where should I put