
Making HTML code run JavaScript
The onclick attribute allows you to make a HTML element interactive. The value of the onclick attribute is set to a piece of JavaScript you want to run when the element is clicked. In this piece of code, when the hyperlink is clicked a JavaScript alert will pop up, telling the user they are being redirected to another website. You can also use a return statement and the value false to stop an onclick from running.
See the Pen M2 CS Making HTML code run JavaScript by Walker Books UK (@walkerbooks) on CodePen.