jmasterx
jmasterx

Reputation: 54103

JavaScript to add class not working?

I have the following JS function:

function addTopLinks() {

    $('#calendar .fc-view-resourceNextWeeks thead th .fc-resourceName')
 .addClass('top-cell');
};

It is not adding the class.

I have another:

function addDayClass() {
    $('#calendar .fc-view-resourceNextWeeks thead th')
        .filter(function () {
            if ($(this).text().indexOf('Mon ') == 0) return true;

            return false;
        })
        .addClass('monday');
};

That one works just fine.

This is the hierarchy:

enter image description here

I am really not sure why the first one is working and not this one...

Thanks

Upvotes: 0

Views: 107

Answers (2)

MarcoK
MarcoK

Reputation: 6110

$('#calendar .fc-view-resourceNextWeeks thead th .fc-resourceName').addClass('top-cell');

should be

$('#calendar .fc-view-resourceNextWeeks thead th.fc-resourceName').addClass('top-cell');

(Note the removal of the space between th and .fc-resourceName)

The first one is looking for another element inside the th with class .fc-resourceName, while you actually want that element.

Upvotes: 1

CD..
CD..

Reputation: 74096

Change your selector, instead of:

'#calendar .fc-view-resourceNextWeeks thead th .fc-resourceName'

try:

'#calendar .fc-view-resourceNextWeeks thead th.fc-resourceName'

Upvotes: 2

Related Questions