Home > Software design >  Add a className if the className has specific CSS property values
Add a className if the className has specific CSS property values

Time:09-29

So far I've tried this code:

jQuery(document).ready(function( $ ){
if ($('.heading-title').css('color') === 'rgb(168, 168, 168)') {
    $('.heading-title').addClass('heading-title-x');
} });

This code adds the class name to each class with "heading-title". But I need to add the class name which only has this specific CSS property value.

CodePudding user response:

Maybe you can try to see each element on document ready.

jQuery(document).ready(function( $ ){
  $('.heading-title').each(function() {
    if($(this).css('color') === 'rgb(168, 168, 168)') {
      $(this).addClass('heading-title-x');
    }
  });
});

(edited)

  • Related