Remove element if next contains value

When creating reports in Confluence sometimes you have to remove a line if the next one contains certain value.

For example, if you have a report in Confluence with a list like this:

  • Line 1
  • No blog posts found.

  • Line 2
  • Blog post 2

  • Line 3
  • Blog post 3

if you want to remove the first like, since it has no blog post found for it, save the following code as a user macro through Confluence admin panel:

## @noparams

<script>
AJS.toInit(function() {
  $(".blog-post-list:contains('No blog posts found.')").parent('li').addClass("hidden");
});
</script>

Then added to the page from Macro selection menu.

Leave a Comment