I want to use the function in the css method of jQuery.

Asked 1 years ago, Updated 1 years ago, 35 views

const color1="red"               
$(`.shape${i}`).css(``background-color`,`${color1}`)

I wrote that, but it doesn't work when I look at it in my browser.I googled a lot, but I couldn't find it.
If you don't mind, I'd like to help you.Please.

javascript jquery

2022-09-29 22:53

1 Answers

The part enclosed by the backquote ` is a single string, so the code provided calls the css() function with one argument: "background-color", "red".

background-color and red are meant to be two separate strings, so

$(`.shape${i}`).css("background-color", `${color1}`);

Or

$(`.shape${i}`).css("background-color", color1);

will be


2022-09-29 22:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.