JS BUTTON CLICK HELP

Status
This thread has been locked.

FelixDev

Typical Developer and Designer
Premium
Feedback score
9
Posts
1,113
Reactions
331
Resources
0
K, So I am trying to make my button change image on the website so if they click the button it changes to another image, here is my current JS and I have no clue to continue making it work.

Code:
    var pics = [
      ".\bilder\bild-1.jpg",
      ".\bilder\bild-2.jpg", // Array
      ".\bilder\bild-3.jpg",
    ];

    var btn = document.querySelector("Button"); // Selectar knappen
    var image = document.querySelector("img"); // Selectar Bilden
    var counter = 1; // Börjar räkningen på en
    if (btn.onclick === true) {
      

    }
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

FelixDev

Typical Developer and Designer
Premium
Feedback score
9
Posts
1,113
Reactions
331
Resources
0
<script type="text/javascript">
function changeImage(a) {
document.getElementById("img").src= a;
}
</script>

<div id="main">
<img id="img" src="test.png">
</div>

<div id="select">
<img src='test1.png' onclick='changeImage("test1.png");'>
<img src='test2.png' onclick='changeImage("test2.png");'>
</div>

And...simple as that ;)

just an example to **help** you out
lol sorry ;) Thanks <<33[DOUBLEPOST=1543317574][/DOUBLEPOST]
Uhm, Im new dude.[DOUBLEPOST=1543317623][/DOUBLEPOST]
<script type="text/javascript">
function changeImage(a) {
document.getElementById("img").src= a;
}
</script>

<div id="main">
<img id="img" src="test.png">
</div>

<div id="select">
<img src='test1.png' onclick='changeImage("test1.png");'>
<img src='test2.png' onclick='changeImage("test2.png");'>
</div>

And...simple as that ;)

just an example to **help** you out
Wait where is the button thingy ?
 
Last edited:

FelixDev

Typical Developer and Designer
Premium
Feedback score
9
Posts
1,113
Reactions
331
Resources
0
As I said this is just an example, the changeImage function is all you needed I just showed you examples on how you can actually use this function to your advantage, I could implement it with your code but for a cheap cost.
lol no thanks,
 
Status
This thread has been locked.
Top