Programming EventHandling
Programming EventHandling
H. Turgut Uyar
Date:
2022-12-11
Version:
0.2
JavaScript
REPL
loop: repeat
Expressions
35 + 7
6 + 7 * 4
Statements
year
year + 250
year * year
Assignment
Math.abs(-42)
Math.pow(1.52, 3.4)
Math.random()
Functions in Expressions
Math.floor(5.92) * 8
Data Types
typeof(42)
typeof(3.14)
typeof(year)
Strings
typeof("ITU")
String Concatenation
object.data
object.method()
String Objects
school.length
school.toLowerCase()
school.replace("T", "C")
Browser Objects
console: console
console.log("Hello, world!");
Window Properties
innerWidth, innerHeight
screenX, screenY
Window Operations
window.alert("Hello, world!");
Document Properties
URL
title
body
Changing Content
document.body.innerHTML = "<h1>BLG101E</h1>";
Changing Style
select by id:
element = document.getElementById("history");
element.style = ...;
element = document.querySelector("#history");
element.style = ...;
Script Elements
<script>
window.alert("Long live The Beatles!");
</script>
External Scripts
<script src="beatles.js"></script>
Events
responding to events
…
Event Attributes
value is code
...
}
Function Example
function tribute() {
window.alert("Long live The Beatles!");
}
Using Function
<script>
function tribute() {
window.alert("Long live The Beatles!");
}
</script>
<body onload="tribute();">
Click Event
<script>
function toggleCallout() {
document.body.classList.toggle("callout");
}
</script>
function toggleCallout(el) {
el.classList.toggle("callout");
}
Passing Elements
<p onclick="toggleCallout(document.body);">
Their famous lineup...
<p onclick="toggleCallout(this);">
Their famous lineup...
Mouse Events