title: Handle Click Events with JavaScript using the onclick property
challengeType: 6
---
## Description
<sectionid='description'>
You want your code to execute only once your page has finished loading. For that purpose, you can attach a JavaScript event to the document called <code>DOMContentLoaded</code>. Here's the code that does this:
You can implement event handlers that go inside of the <code>DOMContentLoaded</code> function. You can implement an <code>onclick</code> event handler which triggers when the user clicks on the element with id <code>getMessage</code>, by adding the following code:
testString: 'assert(code.match(/document\.getElementById\(\s*?(''|")getMessage\1\s*?\)/g), ''Your code should use the <code>document.getElementById</code> method to select the <code>getMessage</code> element.'');'