Javascript, jQuery | Type: JavascriptjQuery Better Show-Hide

A show-hide that still works (last used mid-2021); changes toggle content.

jQuery(function($) {
    $(document).ready(function() { // this tells jquery to run the function below once the DOM is ready
var showText="Show"; // choose text for the show/hide link
var hideText="Hide";
    $(".toggle").prev().append(' <a class="toggleLink" href="#">'+showText+'</a><span class="pointer">»</span>'); // append show/hide links to the element directly preceding the element with a class of "toggle"
    $('.toggle').hide(); // hide all of the elements with a class of 'toggle'
    $('a.toggleLink').click(function() { // capture clicks on the toggle links
    if ($(this).text()==showText) { // change the link text depending on whether the element is shown or hidden
    $(this).text(hideText);
    } else {
    $(this).text(showText);
    }
    $(this).parent().next('.toggle').toggle('fast'); // toggle the display
    return false; // return false so any link destination is not followed
    });
});
});

We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept