a
element’s onClick
attribute. This attribute’s value is valid Javascript code. Trying to place a lot of complicated Javascript code as the onClick
attribute’s value is difficult to edit. The best practice is instead to just add the name of a function followed by the return
statement with the false
keyword as the expression. Also note that the href
attribute’s is set to the hash symbol, #
to disable the default browser action for the a
element.
Testing to See If It Works
You need a web browser console window open that supports the console object for this example. In that console window when you load or refresh the page you will see the messages showRandomNumber() and a random number such as 0.5579135087318718. If your console window was not enabled when you opened this page, then enable and refresh/reload this page to see again.Javascript website skills needed for interactivity: menus, buttons and forms.