Updated specific locations to be searchable, take a look at Las Vegas as an example.

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Trying to change button's image on each click
Post Body

Hey so there's a project I'm working on where I have to change the button's image on each click, changing 2 more times before it stops. At first I thought I would use a for loop to iterate it on each click but was having trouble binding it within the class. I decided to go with a few if statements as part of the eventListener but still having an issue binding it. The logic of it makes sense to me but I'm not sure how to bind it to the class.

I hope my code copy and pasted correctly.

let flowerButton = document.createElement("button");
flowerButton.setAttribute("id", "Flower Button");
document.body.appendChild(flowerButton);
flowerButton.innerHTML = "<img src = ./images/flower/flower0.png>";

class Flower {
  constructor() {
    this.flowerArray = [
      "./images/flower/flower0.png",
      "./images/flower/flower1.png",
      "./images/flower/flower2.png",
    ];
  }


  flowerImageChange() {
    flowerButton.addEventListener("click", function(){
      if ((flowerButton.innerHTML = "<img src = ./images/flower/flower0.png>")) {
        flowerButton.innerHTML = "<img src = ./images/flower/flower1.png>";
      }
      else if ((flowerButton.innerHTML = "<img src = ./images/flower/flower1.png>")) {
        flowerButton.innerHTML = "<img src = ./images/flower/flower2.png>";
      }
    });
  }.bind(flowerImageChange);
}

This is the code with the for loop if it helps but I think my main issue is figuring out how to bind it.

let flowerButton = document.createElement("button");
flowerButton.setAttribute("id", "Flower Button");
document.body.appendChild(flowerButton);
flowerButton.innerHTML = "<img src = ./images/flower/flower0.png>";

class Flower {
  constructor() {
    this.flowerArray = [
      "./images/flower/flower0.png",
      "./images/flower/flower1.png",
      "./images/flower/flower2.png",
    ];
  }
  flowerImageLoop() {
    for (let i = 0; i < this.flowerArray.length; i  ) {
      flowerButton.innerHTML  = `<img src = ${this.flowerArray[i]}>`;
    }
  }
  changeButtonImage() {
    flowerButton.addEventListener("click", flowerImageLoop);
  }
}

Author
Account Strength
100%
Account Age
5 years
Verified Email
Yes
Verified Flair
No
Total Karma
8,957
Link Karma
550
Comment Karma
8,011
Profile updated: 4 days ago
Posts updated: 1 day ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago