1

I apply the below script to add color to the comments I add in my application (JIRA).

<script type="text/javascript">
$(document).ready(function() {
    $(".activity-comment:even").css("background-color","#6699FF"); 
    $(".activity-comment:odd").css("background-color","#B2CCFF"); 
});

comments http://i.minus.com/jFoE7kcaTqdrp.JPG

After applying the script the comments appear as above , however the script does not work when i move to other tabs (i.e. Worklog , History) or i add a new comment. I need to refresh the page for the script to execute .

Can someone please help me how i can permanently set the colors ?

Note : I am applying the javascript on the application announcement banner this makes the script run on every page of the application , I can make changes to the source files.

Thanks in Advance :)

1
  • you mean an additional CSS file which will do this ? can you please provide an example ?
    – Mizan
    Jan 18, 2013 at 6:51

1 Answer 1

1

I think you can achieve this thing in 2 ways:

1- By using CSS: In your css file just add following lines of code:

.activity-comment:even{
    background-color: #6699FF;
}
.activity-comment:odd{
    background-color: #B2CCFF;
}

2- By Jquery: In this case use .live() function of jquery to achieve style on dynamic added comments. Like get the id of comment submit button (suppose: comment_add) , and then:

$("#comment_add").live('click',function(){
    $(".activity-comment:even").css("background-color","#6699FF"); 
    $(".activity-comment:odd").css("background-color","#B2CCFF");
});

I think it will help you.

5
  • live is deprecated, use on instead
    – JFK
    Jan 18, 2013 at 7:08
  • @Workonphp , I want to go with CSS as there are many ways of adding a comment and user can toggle between the tabs . I tried your CSS solution but unfortunately it is not working . Can you please help . Thanks
    – Mizan
    Jan 18, 2013 at 9:26
  • 1
    Mizan: Can u try it with jquery also, I think it will not be a big deal.
    – Workonphp
    Jan 18, 2013 at 9:29
  • jquery is also not working , when i add a comment there are some ajax request sent I used firebug to find this .
    – Mizan
    Jan 18, 2013 at 9:52
  • I was able to resolve this by using the setInterval() where i execute the css ever 100ms .
    – Mizan
    Jan 21, 2013 at 9:55

Your Answer

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

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