-1
Program structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<section onclick = 'clicar()'>
<div id = 'a1'></div>
<div id = 'a2'></div>
<div id = 'a3'></div>
</section>
<script>
var a1 = document.getElementById('a1').innerHTML
var a2 = document.getElementById('a2').innerHTML
var a3 = document.getElementById('a3').innerHTML
function clicar(){
//DÚVIDA
}
</script>
</body>
</html>
How would I identify within Function 'click()'which Ivs the user would be clicking? ('a1', 'a2', 'A3').
Example:
if (click == 'a1'){
window.alert('Carro comprado')
}else if (click == 'a2'{
window.alert('Carro vendido')
}else if (click == 'a3'){
window.alert('Carro reembolsado')
}
I hope it’s clear.
Do you have any video lesson to recommend me to dig deeper into this subject? (this, Arguments and Events)
– YogSothothUmbral
Video lesson? No have no, I know the documentation of MDN and W3schools.
– Andre
But how would I select that div later? Ex:
if (a1 == 'X')
I tried to maketarget.a1
ortarget.innerHTML.a1
but of Undefined and not the value I put before ('X').– YogSothothUmbral