6
I have a work course and I had the following idea:
There are several images that will represent the chairs of a cinema (all are the same images, the same are in my HTML file), and I want to make the effect that when the user clicks on one of them it changes color symbolizing that he chose that chair.
I want to use the "onClick" so that it calls another image when clicking on the images that are appearing to the user or it will call the same image only of different color.
I want it to be by that method but I don’t know if it’s possible, if you’re not going to show me the best possible way to do it.
My HTML file
<div>
<img src="imagens/cadeiraAzul.png" id="cadeira1" onclick="">
</div>
My JS file
function cor(){
}
Since I’m a beginner in this area you’ll probably have tools unknown to me so if you can explain what each one does I’ll be even more grateful.
I also need that if the user clicks again it change to image that was initially, for if it is chosen by mistake.
In this method, just change the attribute
src
image. Use the methodsetAttribute('src', 'caminhoDaNovaImagem')
. Detail, if you want "multiple chairs" in HTML, stay tuned toid
of each image, because ID is unique, can not repeat.– Douglas Garrido
In this case where I would use the "setAttribute" ?
– Lone Tonberry
In its function of
onclick
. See more information here W3schools.– Douglas Garrido
In that question has several cool answers that you can use in your application.
– Taisbevalle