0

I'm trying to select calendar event titles that have a specific word and use this to change the background colour of the event.

Please see my code below. This changes all events to have the background colour of red even if event title doesn't contain the word 'Test'. I've even changed 'Test' to 'uhrguqhergoieqhrgeurgherogih' but it still changes everything.

Unfortunately I can't see anything similar on SO so hopefully one of you could help me out please! :)

Thanks in advance!

$(window).on('load', function() {
    if($(".fc-event-title:contains('Test')"))
    {
      $('.fc-event').css('background-color', 'red');
    }
});
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
S.Pearson
  • 123
  • 1
  • 1
  • 9

1 Answers1

1

No need of if condition.Do it directly like below:-

$(window).on('load', function() {
  $(".fc-event-title:contains('Test')").css('background-color', 'red');
});

If above not worked then try with closest() like below:-

$(window).on('load', function() {
  $(".fc-event-title:contains('Test')").closest('.fc-event').css('background-color', 'red');
});
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98