Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1334630
    kendricka
    Participant

    Hi there,

    I am using Edit Global Javascript to execute a couple of scripts, to expand and collapse the div content in some Archive widgets. Everything works well when I use an element selector, but as soon as I use $(this) the custom javascript window won’t save and my site has a gateway timeout 504 error.

    This script works for each archive element:

    jQuery(function($){
    $(‘#nav_menu-8 h4’).click(function(){
    $(‘#nav_menu-8 div’).toggleClass(‘show’);
    });
    });

    However, as the number of archives grow I want to write a one size fits all script, eg:

    jQuery(function($){
    $(‘.widget_nav_menu h4’).click(function(){
    $(this).next(‘div’).toggleClass(‘show’);
    //there will be another line here to collapse other open archives
    });
    });

    Bear in mind all my widgets have the same html structure, ie:

    <div id=”#uniqueid” class=”widget_nav_menu”>
    <h4>Archive name</h4>
    <div>Hidden articles</div>
    </div>

    Looks totally plausible and I’ve used this for other non-wp related jobs, but as soon as “(this)” is applied to the Global Javascript it breaks everything.

    I hope you can help…

    thanks,
    Adrian

    #1334679
    Paul R
    Moderator

    Hi Adrian,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #1335826
    kendricka
    Participant
    This reply has been marked as private.
    #1336187
    Rupok
    Member

    Hi Adrian,

    Do you have more code to place on the Custom JS? In that case share the code here (don’t forget to wrap with code tag from Toolbar). I can see two blocks of code right now and seems working. Give us the code that’s not saving.

    Cheers!

    #1340903
    kendricka
    Participant

    Hi Rupok,

    This is the code which wasn’t working. I have tested outside of wp and all seems fine with it.

    I’d like this to *replace existing code* in the Global javascript section.

    jQuery(function($){
    	$('.widget_nav_menu h4').click(function(){
    		$(this).next('div').toggle();
    		$(this).parent().siblings().children().next().hide();
    	});
    });
    #1340904
    kendricka
    Participant

    false alarm mate, I’ve just pasted this in and it’s behaving itself. Not sure what was wrong first time around…

    Thanks
    a

    #1341033
    Rue Nel
    Moderator

    Hello There,

    Thanks for updating in! We’re just glad that you were able to figure out a way to resolve the issue.
    If you have anything else we can help you with, please do not hesitate to create a separate thread.

    Regards.

  • <script> jQuery(function($){ $("#no-reply-1334630 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>