Change CSS on click of button

I’m trying to change the CSS of an image that is choosen when the user inputs a name. Currently I have this and it works:
$('.' + userInput).css("box-shadow", "0 0 40px #FFE9D5");

However, when the user inputs another name the CSS stays on the first image selected and also moves to the next image. I’m trying to get it to only stay on the selected input. I thought the code below would work, but it does not. Any suggestions?

  $(".myBtn").on("click", function() {
      if('.' + userInput === planets[i].name) {
        $('img').css("box-shadow", "0 0 40px #FFE9D5");
      } else {

(I realize this might be tough without seeing the rest of my code. Let me know!)

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


1 Like