jeudi 4 février 2021

If something has a certain attribute then I want that certain elements style to change

Sorry if it's such a basic question for some of you but I'm struggling.

Here is what I'm trying:

   var hasPurple = $(this).attr('data-attrs','{"attribute_pa_flavours":"lavender"}');

   $(function () {
     if ($(hasPurple !== undefined && hasPurple !== false)) {
       $(this).attr('style','background-color: purple');
     } else {
     }
   })

Aucun commentaire:

Enregistrer un commentaire