Hello classmates I have the following code which the purpose is depends on which button you show an image and the name of the character, the image shows it to me and its name but in the first it works correctly but in the second it does not work it works because the name of the first one continues to follow me and also the one that corresponds to it.
The truth was I was thinking about another function in which I would handle this problem but it is something tangled which would probocaria pasta code?
What do you think?
My Current Code:
<!DOCTYPE html>
<html>
<body>
<title>Mario Bros</title>
<script type="text/javascript">
function red(){
document.getElementById('myImage').src='indice.jpeg';
document.getElementById("mario").innerHTML = "Mario Bros";
}
function verde(){
document.getElementById('myImage').src='luchi.jpeg';
document.getElementById("luchi").innerHTML = "Luchi";
}
</script>
<h1>Mario Bros</h1>
<img id="myImage" src="http://www.esucesos.com/wp-content/uploads/2015/09/mario-bros.-1.jpg" style="width:100px">
<p id="mario"></p>
<p id="luchi"></p>
<button onclick="red();">Mario</button>
<button onclick="verde();">Luchi</button>
</body>
</html>