conflunce html macro

i used a html macro to display a static table. A small piece of javascript is used to highlight the rows depending on table values. this works well on the preview screen. however, in the actual view, color highlight is no where to be found. does anybody know what is going on here?

below is my code in html macro:

<html>
<head>
<script type="text/javascript">

$(document).ready(function(){
$('#report td.status').each(function(){
if ($(this).text() == 'failed')

{ $(this).css('background-color','red'); }

if ($(this).text() == 'passed')

{ $(this).css('background-color','green'); }

});
});

</script>

</head>
<body>

<table id="report">
<tr><th>Builds</th><th>Status</th></tr>
<tr><td>1</td><td class="status">failed</td></tr>
<tr><td>2</td><td class="status">passed</td></tr>
<tr><td>3</td><td class="status">passed</td></tr>
<tr><td>4</td><td class="status">failed</td></tr>
</table>

</body>
</html>

1 answer

1 vote
Steven Behnke Community Champion Apr 01, 2016

This alternative works. Please note – 

  • Use AJS.toInit instead of document.ready
  • Use AJS.$ instead of $
  • Don't place <head><body>, or <html> tags in the macro

 

&lt;script type="text/javascript"&gt;
AJS.toInit(function(){
  $('#report td.status').each(function(){
    if ($(this).text() == 'failed') { 
      AJS.$(this).css('background-color','red'); 
    } else if (AJS.$(this).text() == 'passed') { 
      AJS.$(this).css('background-color','green'); 
    }
  });
});
&lt;/script&gt;
&lt;table id="report"&gt;
  &lt;tr&gt;
    &lt;th&gt;Builds&lt;/th&gt;
    &lt;th&gt;Status&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;1&lt;/td&gt;
    &lt;td class="status"&gt;failed&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;2&lt;/td&gt;
    &lt;td class="status"&gt;passed&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;3&lt;/td&gt;
    &lt;td class="status"&gt;passed&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;4&lt;/td&gt;
    &lt;td class="status"&gt;failed&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Tuesday in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

435 views 18 9
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you