# How can I add a custom class to every 2nd message?

**URL:** <https://meta.discourse.org/t/how-can-i-add-a-custom-class-to-every-2nd-message/49990>\
**Category:** Support\
**Created:** [2016 年 9 月 11 日午後 7:37 UTC](https://meta.discourse.org/t/how-can-i-add-a-custom-class-to-every-2nd-message/49990 "2016-09-11T19:37:43Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![ziptofaf](https://avatars.discourse-cdn.com/v4/letter/z/ee7513/32.png) [@ziptofaf](https://meta.discourse.org/u/ziptofaf)\
**Post date:** [2016 年 9 月 11 日午後 7:37 UTC](https://meta.discourse.org/t/how-can-i-add-a-custom-class-to-every-2nd-message/49990/1 "2016-09-11T19:37:43Z")

</div>

Okey, there’s a huge chance I am just very stupid and can’t see the obvious but I am wondering on how to write a plugin/extension that will simply add one extra class to every 2nd .topic-body. Reason for why I need it is to add a different background color for them (and doing it via sheer CSS is pretty hard considering they are all in separate rows etc). So I can get to this result:

 ![](https://global.discourse-cdn.com/meta/original/3X/1/7/17844fe1c1f315be56685304315c99f86a273345.png)

Right now I am using a timer based approach [that I’ve seen here](https://meta.discourse.org/t/catch-content-loaded-event-via-js/26323/3?) but it’s actually not firing every time, once in a while it fails to do so after loading next batch of posts. Which annoys me a lot.

So I’ve come to a conclusion that I need to either understand when exactly does Discourse loads new messages (aka which event causes it) or that it should be done server-side, at the render time. However I am at a loss on how to implement it, it seems I am really lacking experience with AJAX heavy development. Any advice or at least a link to some resources that could help me here would be awesome

---

_[View the full topic](https://meta.discourse.org/t/how-can-i-add-a-custom-class-to-every-2nd-message/49990)._
