Example: Using event listeners and this

In this example, we add event listenersA function that is executed when an event occurs. to two different buttons. By using this, we can use the same function for both.

Notice the use of setAttribute to change the attributeExtra information added to an element., as mentioned in the discussion on extracting information in the DOM.

Note:

Hints:

  • undefined
1
2
window.onload = startFunction;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
<!DOCTYPE html>
<html lang="en">
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX