0

I have the following function in my Meteor project:

function populate(){
  //console.log(Calendar.find().count())
  var dates = Calendar.find().fetch();
    for (var i = 0; i < dates.length; i++){
        var today = new Date(dates[i].date);
        //console.log('tbody.event-calendar tr td[date-month="' + (today.getMonth() + 1) + '"][date-day="' + today.getDate() + '"]')
        $('tbody.event-calendar tr td[date-month="' + (today.getMonth() + 1) + '"] [date-day="' + today.getDate() + '"]').addClass('event');
    }
}  

When I uncomment the console.logs I get the correct count and code such as: $("tbody.event-calendar tr td[date-month="8"][date-day="26"]").addClass("event") for the dates loops.

What's weird is that if I remove the variable in the jQuery and hard code a number (substitute today.getMonth() with 8 and today.getDate() with 1) the code works as expected.

What's causing my jQuery not to work with variables?

1 Answer 1

4

Try without a space between date-month and date-day:

$('tbody.event-calendar tr td[date-month="' + (today.getMonth() + 1) + '"][date-day="' + today.getDate() + '"]').addClass('event');
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, I had it without the space before and I added the space while debugging another issue... Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.