SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following JQuery code entered into a content editor web part which does some conditional formatting on the table cell of a list. The trouble with this is that it executes fine on document ready but when the user clicks a "next" image on the pagination area or clicks a column header to sort the list the page is not actually reloading so the formatting does not work. What is the best way to insure any click even on the list table would execute the formatting?

$(document).ready(function () {
$('tbody"Green")').css("background-color", "green").css("color", "white");

$('tbody"Yellow")').css("background-color", "Yellow").css("color", "Black");   

$('tbody"Red")').css("background-color", "Red").css("color", "White");   
share|improve this question

Another way to do this is to modify the XSLT and do your formatting there. Then you wouldn't need the jQuery dependency.

share|improve this answer
I'd do this unless SPD is off limits (and thus the need for a jQuery solution). – Eric Alexander Jun 21 '12 at 16:55
Good call. Thanks. – Steve Lineberry Jun 21 '12 at 16:57
I am thinking i need jquery here because the users change the columns a lot. I have it working mostly now. However it only works on the first click . The second click does not execute my code for still unknown reasons. – ChiliYago Jun 21 '12 at 20:25
Right, I understand the issue, I was just providing an alternate solution where you don't have to worry about the update panel postbacks and executing your JS. If you modify the xslt, you can change the actual html on the page. No JS needed. – Steve Lineberry Jun 22 '12 at 0:35

I would suggest trying to determine what JS event is being called when the page refreshes and doing a double delegate on that function to run your code.

I've never used it before but I've heard other's having good success using eventbug for firefox to try to find these type of JS events.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.