代表者の戯言

clickEvent



This time, I want to introduce clickEvent to you.There is also another way of clickevent,for example


document.querySelector('#ID').addEventListener('click', () => {


});


But,mybe this will be easier to understand.


******************************************************************************************************

<!DOCTYPE html>


<html lang="ja">


<head>


<meta charset="UTF-8">


<title></title>


<link rel="stylesheet" href="reset.css">


<link rel="stylesheet" href="main2.css">


</head>


<body>


<div class="container">


<img src="picture/white.jpg" onClick="clickevent(event)">


<img src="picture/white.jpg" onClick="clickevent(event)">


<div id="output">


</div>


</div>


<script type="text/javascript">


function clickevent(event){


var obj=event.target;


if(obj.src.includes("white.jpg")){


obj.src="picture/black.jpg";


}else{


obj.src="picture/white.jpg";


}


}


</script>


</body>


</html>


******************************************************************************************************
screen