Search results
The onclick event occurs when the user clicks on an HTML element. onclick is a DOM Level 2 (2001) feature. It is fully supported in all browsers: Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
- Try It Yourself
Try out JavaScript code snippets in the W3Schools Tryit...
- Try It Yourself
The onclick attribute fires on a mouse click on the element. Applies to The onclick attribute is part of the Event Attributes , and can be used on any HTML elements.
8 lis 2024 · The onclick event attribute in HTML triggers when the user clicks on an element. It executes a script or function upon a click event and is commonly used for interactive elements like buttons and links.
Example Click on a <button> element to display the current day, date and time: <button onclick="getElementById('demo').innerHTML = Date()">What is the time?</button>
If you want to make a button onclick, you need to add the onclick event attribute to the element. Learn How to Make Button Onclick with Examples.
24 lip 2012 · Whether that results in file.doc being downloaded or being shown as a page in the browser depends upon the headers returned by the server when it serves file.doc and on what file types the browser is capable of rendering. A simple JS solution: const a = document.createElement('a') a.href = url. a.download = url.split('/').pop()
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.