Published by Patrick Mutisya · 14 days ago
Know and understand that the behaviour layer is for a scripting language to control elements within a web page.
The behaviour layer sits on top of the content (HTML) and presentation (CSS) layers. Its purpose is to add interactivity, respond to user actions, and manipulate the document structure while the page is displayed.
When a web page loads, the browser creates a Document Object Model (DOM). The scripting language can:
getElementById, querySelector, appendChild, and removeChild.setTimeout and setInterval for delayed or repeated actions.The following JavaScript code changes the text of a paragraph when a button is clicked.
<button id="myBtn">Click me</button>
<p id="myPara">Original text.</p>
<script>
document.getElementById('myBtn').addEventListener('click', function() {
document.getElementById('myPara').textContent = 'Text updated by JavaScript!';
});
</script>
| Layer | Primary Technology | Purpose |
|---|---|---|
| Content | HTML | Structure and semantics of the page. |
| Presentation | CSS | Visual styling and layout. |
| Behaviour | JavaScript (or other scripting language) | Interactivity, dynamic changes, event handling. |
innerHTML (adds HTML markup) and textContent (adds plain text).event.preventDefault()) when handling form submissions.