Javascript onclick example
How to create JavaScript click example at the image?
Example:
Example:
<img src="images/fl1.jpg" alt="Anything learn">
<script>
var anyImg = document.querySelector('img');
// console.log(anyImg);
anyImg.onclick = function(){
var anySrc = anyImg.getAttribute('src');
if(anySrc === 'images/fl1.jpg'){
anyImg.setAttribute('src','images/fl2.jpg');
}
else{
anyImg.setAttribute('src','images/fl1.jpg');
}
}
</script>
No comments:
Note: Only a member of this blog may post a comment.