Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2009
    Posts
    158
    Thanks
    71
    Thanked 1 Time in 1 Post

    append class if...

    Hi, I was just wondering. I create a string like so
    Code:
    var currentDate = new Date(year, month-1, item);
    returnValue = "<table><tr><td class='day-align'>"+currentDate.getDate()+"</td>";
    returnValue += "<td class='month-align'>"+ monthString[currentDate.getMonth()]+"</td>";
    returnValue += "<td class='year-align'>"+currentDate.getFullYear()+"</td>";
    returnValue += "<td class='weekday-align'>"+"("+weekday[currentDate.getDay()]+")"+"</td></tr></table>";
    var $li = $("<li/>").addClass("ui-li ui-li-static ui-btn-up-c comp-align").html(returnValue).appendTo($list);
    So I build up returnValue based on the currentDate, and then I add it to a list which displays the date. The problem is, in the above code, if
    Code:
    weekday[currentDate.getDay()]
    is equals to Saturday or Sunday, I want to apply another class which will change the background colour of the list item. Is something like this possible?

    Thanks

  • #2
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    you already know how to add class, so why not use this:
    Code:
    if(weekday[currentDate.getDay()] == 'Saturday' || weekday[currentDate.getDay()] == 'Sunday'){
        $('#dayId').addClass('whateverClass');
    }
    you just need to add id when you construct your string (and add it to your page of course)
    Last edited by patryk; 04-14-2013 at 11:47 PM.

    -------------------------------------------------------------------------------
    "Real Programmers can write assembly code in any language" - Larry Wall


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •