2021-04-30

Adding element class if background color is blue

I am pretty new to javascript and I am working on a page and trying to get a class added to an element based on the element's background color, if it is set to rgb(32, 44, 62) I want to add a class to the element. As it is coded now it adds it to all matching elements not just the ones with the background color. Below is my test of the code. Any insights would be extremely helpful.

https://codepen.io/tyearyean/pen/PoWvLwO

var basicBGColor = $('section.content_basic').css('background-color');

Javascript

    var basicBGColor = $('section.content_basic').css('background-color');

    $('section.content_basic').each(function() {
      if (basicBGColor == 'rgb(32, 44, 62)') {
        $(this).addClass('goldBorder');
      };
    });


from Recent Questions - Stack Overflow https://ift.tt/3e6CMpo
https://ift.tt/eA8V8J

No comments:

Post a Comment