Trying to Add something like a Heading on top of a category

AI-generated summary

Daniel_Nevoigt is seeking help to add a heading above a specific forum category using jQuery. He initially tried inserting the heading via $(document).ready(), which worked on the first page load but disappeared upon navigating back. When he switched to using $(document).ajaxComplete(), the heading appeared multiple times. He later resolved the issue by referencing a solution from a Meta Discourse thread, crediting cpradio for the guidance. The core challenge was ensuring the heading persisted dynamically across page transitions without duplication.

Hello all,

I am trying to set a heading for different groups of forum categories I have. Perhaps someone can point me to the right direction. I was trying to use jquery method but I get stuck with only loaded the heading-element when page load is ready what results the heading only shown once on homepage, when returning the element disappeared. Second way I get stuck with elements loading multiple times :smile:

Let me break it for you:

I am using that function to add the element:

$('tr[data-category-id="9"]').before ('<tr><td class="category" style="border-color: #F37022;">My Heading</td><td class="topics"></td><td class="latest"></td></tr>');

So, inside document ready function is the first scenario, works well, but when browsing the forum and than going back to start page, the element is gone.

When doing the following, the element loads multiple times:

function OnLoad (){
    $('tr[data-category-id="9"]').before ('<tr><td class="category" style="border-color: #F37022;">Eve Online</td><td class="topics"></td><td class="latest"></td></tr>');
}
$(document).ajaxComplete(function () {
    OnLoad();
});

Perhaps someone knows what to do, that would be great :slight_smile:

Cheers, Daniel

Ok, to solve that question:

Thanks to @cpradio