@DownPW I remember this same issue now when I came across it whilst writing the threaded
function. The problem here is that [component="topic/necro-post"]
actually isn’t present in the DOM on page load, but added afterwards. This is why once the page has loaded, you can target the element with the toggle switch because it is in the DOM at the time. Because the this specific element is loaded afterwards, you cannot target it if it doesn’t exist.
This effectively means you cannot add a class to an element that is not there. To work around this, you’d either have to wait for the page to load, add the necro
element, then target it.
Or, use the CSS I provided, and then “counter” it using other CSS when the class is removed. This is what I do in thwe threaded
function.
Raised this as an issue here
https://community.nodebb.org/topic/17590/necro-function-dom-changes
EDIT - should work now
I’ve added a loop in your material
function that looks specifically for the necro post
$('[component="topic/necro-post"]').each(function () {
// Add the 'material' class to matching elements
if ($(this).hasClass('timeline-event')) {
$(this).addClass('material');
}
});
And also (on the advice of Baris) added a new hook as below
$(window).on('action:topic.loaded', function (data) {
material();
});
There are two separate hooks that look very much the same, but do different things (one has an “s” at the end, whilst the other doesn’t - “action:topic.loaded” and “action:topics.loaded”
Now it works as intended