From 588e25e5d0a30c25ca952ccaa1a2f1f1c92a03f6 Mon Sep 17 00:00:00 2001 From: ​ Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: rescue --- rescue/10/question.txt | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 rescue/10/question.txt (limited to 'rescue/10/question.txt') diff --git a/rescue/10/question.txt b/rescue/10/question.txt new file mode 100644 index 0000000..922968d --- /dev/null +++ b/rescue/10/question.txt @@ -0,0 +1,38 @@ +Question: +In this exercise, you used an onclick event handler to call +each function. Research the addEventListener() method, and +explain how you would use it instead of an onclick event +handler to call the functions. + +Answer: +To use addEventListener(), I would replace the HTML onclick +attributes with ID attributes. I could then use addEventListener() +in combination with document.getElementById() to run a specific +function depending on which HTML paragraph is clicked. + +HTML: +
+
+

How can I determine if a baby animal + is an orphan?

+

How can I tell if an animal has + rabies?

+

I found a baby bird that fell from + its nest. Will the parents orphan it if I touch it?

+

How can I volunteer?

+
+
+

Answer:

+

+
+
+ +JS: +var q1 = document.getElementById("q1"); +q1.addEventListener("click",ans1); +var q2 = document.getElementById("q2"); +q2.addEventListener("click",ans2); +var q3 = document.getElementById("q3"); +q3.addEventListener("click",ans3); +var q4 = document.getElementById("q4"); +q4.addEventListener("click",ans4); -- cgit 1.4.1