Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Javascript code is not working properly in confluence page/html-macro

I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 18, 2024

I wrote a js function to hide rows in a table based on some criteria, 

I tested the code offline on local files and it worked properly with no errors

I implemented the same code in confluence page and it doesn't even work. I am sure my code is not the problem because it worked offline on a downloaded version of  the confluence page and a simple html table I made before.

This is my code:


function filter_rows(index, parentID) {
    var rows = document.getElementById("element_matrix").rows;
    var options = document.getElementById(parentID).getElementsByTagName('label')
    var checkboxes = document.getElementById(parentID).getElementsByTagName('input')
    for (let i = 0; i < options.length; i++) {
        if (checkboxes[i].checked) {
            if (!hashmapOfoptions[index].includes(options[i].innerText)) {
        } else {
            hashmapOfoptions[index] = hashmapOfoptions[index].filter(item => item !== options[i].innerText)

    for (var row = 1; row < rows.length; row++) {
        var cols = rows[row].cells;
        willHideRow = true
        for (let j = 0; j < cols.length; j++) {
            willHideRow &= hashmapOfoptions[j].includes(cols[j].innerText)
        if (!willHideRow) {
            rows[row].style.display = 'none'
        } else {
            rows[row].style.display = '' // this


When using a debugger I noticed all lines are executed but their effects don't always happen.

I am 100% sure the problem isnt with my code 

1 answer

0 votes
Andrii Maliuta
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 22, 2024

Hello @ahmad ,

Could you please clarify how you inject the code into the Confluence page?

If you use  out-of-the-box HTML macro, then you can use <script> tag to apply the code and if you use JS in the plugin modules it should be inside AJS.toinit() and so on.

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events