Page 1 of 1

Color rows doesn't work with Safari

Posted: Wed Oct 31, 2018 10:40 am
by marcvander
Hey,

I have had this JS running and working perfectly under Chrome browser:

Code: Select all

if (nuFormType() == 'browse') {

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
    dd = '0'+dd
} 

if(mm<10) {
    mm = '0'+mm
} 

today = yyyy + '-' + mm + '-' + dd;

    $('[data-nu-column="0"]').each(function (index) {

        var cellId = $(this).attr('id');
        var cellValue = $('#' + cellId).html();
        var rowNum = String(cellId).split('_')[1];

        if (cellValue < today) {
            $("div[id^='nucell_" + rowNum).css("color", "red");
        }
        if (cellValue == today) {
            $("div[id^='nucell_" + rowNum).css("color", "green");
        }
    });
}
It basically colors in red if current date > date value in row, and in green if current date == date value in row.

It doesn't work under Safari browser. Here is the error I get in Safari console:
Error: Syntax error, unrecognized expression: div[id^='nucell_0 error jquery.js:1586

I guess the expression has to be stated differently for Safari, but how?

Thanks

Marc

Re: Color rows doesn't work with Safari

Posted: Wed Oct 31, 2018 12:37 pm
by kev1n
Your syntax is incorrect. You're missing a ] so the error is correct. Chrome is lenient and closes the selector for you but Safari obviously doesn't.

Replace

Code: Select all

$("div[id^='nucell_" + rowNum).css("color", "red");
With

Code: Select all

$("div[id^='nucell_" + rowNum + "']").css("color", "red");

Re: Color rows doesn't work with Safari

Posted: Thu Nov 01, 2018 10:08 am
by marcvander
Ah damnit! Indeed it works now on Safari

Thanks :)

Re: Color rows doesn't work with Safari

Posted: Fri Nov 02, 2018 2:43 am
by admin
.