Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
166
rated 0 times [  173] [ 7]  / answers: 1 / hits: 15562  / 11 Years ago, tue, may 14, 2013, 12:00:00

i'm trying to make a timetable for a Moodle in form of a Greasemonkey script.



The idea is to highlight the subject for the current hour, but i can't find a working way of doing it.



I'm injecting css into the page, and using jQuery to add the injected css class to the target td.



This is the css code injected into the page header:



.current_class {background-color:green};


And this is the javascript code used to add the class to the td:



var cell = $(#timetable_table).find(tr).eq(current+1).find(td).eq(date.getDay());


I know cell is the correct td because i can cell.text(foo) and the correct cell is modified, but when i do:



cell.addClass(current_class);


the table stays the same.



I don't have to do it that way, i only want to dynamically change the background on a td tag, so i don't mind using other methods.



Thanks.


More From » jquery

 Answers
3

First I would suggest you change to this:



var cell = document.getElementById('timetable_table').rows(current+1).cells(date.getDay());


And:



cell.className += (cell.className ?   : )+current_class;


But that's just for performance reasons



The probable cause of the issue is that you have background-color being defined elsewhere with greater specificity. Try using this CSS selector:



#timetable_table tr>td.current_class{background-color:green};


That should be specific enough to win.


[#78234] Monday, May 13, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keyonna

Total Points: 521
Total Questions: 104
Total Answers: 96

Location: Samoa
Member since Tue, May 3, 2022
2 Years ago
;