I'm designing a webpage which uses very basic javascript. Here's the code:
html:
<!DOCTYPE html>
<html>
<body>
<img id="apple" onclick="display()" src="images/apple.jpg" width="150" height="150">
<img id="pineapple" onclick="display()" src="images/pineapple.jpg" width="130" height="210">
<br><br>
<div id="description" style="width:300px;height:100px;border-top: 1px solid #000; border-bottom: 4px solid #000; border-left: 2px solid #000;
border-right: 4px solid #000;padding: 5px;"></div>
<br>
<button type="button" onclick="reset()">Reset</button>
<script type="text/javascript" src="obst.js"></script>
</body>
</html>
Here's the javascript:
function display()
{
document.getElementById("description").innerHTML="der Apfel - Apple<br>die Äpfel - Apples<br><br>Ein Apfel am
Tag hält den Arzt weg<br>- An apple a day keeps the doctor away";
}
function reset()
{
document.getElementById("description").innerHTML="";
}
Clicking on the image of the apple displays text in the description box. Clicking on the image of the pineapple displays some other text in the same place.
Instead of using different functions like apple(), pineapple() to insert text, I thought it would be easier to call a display function whenever something is clicked, and in the display function, if the script could identify the source of the click (that is, which image is clicked), it could insert text accordingly.
How do I go about this identifying the click source?