Skip to content
Advertisement

how to solve card does not change colour using javascript function

I want to implement this feature, the card element will turn grey color when the product_stock == 0. I tried to implement this feature using javascript but it does not work. I do not know what is wrong with my codes. Can anyone of you help me with this issue? It would be appreciated if you guys can show me examples of codes on how to solve this issue. Any help will be appreciated. Thanks!

This is my PHP codes

JavaScript

This is the javascript that i used to make the card into grey colour when the product_stock = 0

UPDATED JAVASCRIPT CODE

JavaScript

Advertisement

Answer

it’s because the product_stock variable is undefined when you call it on the script. instead of using javascript code, just add the style directly to the PHP code.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement