Don't work after reload (script js)

Allan

Well-known member
Hey, i test this script:

Code:
<!--
$('.categoryNodeInfo').prepend("<div class='showhideNodes hideNodes'>{xen:phrase showhideNodes_collapse}</div>");
var showhideNodesCookie = $.getCookie('showhideNodes');
var showhideNodesArray=new Array();
if (showhideNodesCookie) {
showhideNodesArray = showhideNodesCookie.split(",");
$.each(showhideNodesArray,function(){
        var selector = 'li[id='+this+']';
        $(selector+' ol.nodeList').hide();
        $(selector+' .showhideNodes').toggleClass('showNodes');
        $(selector+' .showhideNodes').toggleClass('hideNodes');
        $(selector+' .showhideNodes').text('{xen:phrase showhideNodes_expand}');
});
}
$('.showhideNodes').click(
function() {
if ($(this).text() == '{xen:phrase showhideNodes_collapse}') {
    $(this).parent().next().slideUp();
    $(this).text('{xen:phrase showhideNodes_expand}');
    //if($.inArray(this,showhideNodesArray) != -1){
        showhideNodesArray.push($(this).parent().parent().attr('id'));
        $.setCookie('showhideNodes',showhideNodesArray.join(","));
    //}
}
else if ($(this).text() == '{xen:phrase showhideNodes_expand}') {
    $(this).parent().next().slideDown();
    $(this).text('{xen:phrase showhideNodes_collapse}');
        var remove = $(this).parent().parent().attr('id');
        showhideNodesArray.splice($.inArray(remove,showhideNodesArray),1);
        $.setCookie('showhideNodes',showhideNodesArray.join(","));
}
$(this).toggleClass('showNodes');
$(this).toggleClass('hideNodes');
});
//-->

It works once and after reloading the page doesn't work.

I have this error in console:

Screenshot_1.webp

What about you?
 
This line is wrong:

Code:
var selector = 'li[id='+this+']';

The correct way to specfy an element with an ID would be:

Code:
var selector = 'li#' + this;
 
This line is wrong:

Code:
var selector = 'li[id='+this+']';

The correct way to specfy an element with an ID would be:

Code:
var selector = 'li#' + this;
The reload work now ! Thank you Chris :)

But don't keeps the user preferences (cookies) :(
 
No idea. You'll maybe need to be specific. Are they not setting? Not getting? Some other issue?
 
Top Bottom