Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<div id="main">
    <div class="container-fluid">
        <div class="col-md-12">
            <form method="post" accept-charset="utf-8" id="searchRegulations" action="https://codepen.io/diegoperini/pen/EpbNyL.html" onsubmit="getAjaxFilters(); return false;">
                <button id="loadFiltersBtn" class="btn btn-success">Load Filters</button>
            </form>
        </div>
    </div>
</div>

<div id="ajaxContent">
</div>

              
            
!

CSS

              
                .active { background-color: #ff0; }
#main, #ajaxContent { margin: 16px; }

              
            
!

JS

              
                // the delegation setup is a capturing phase listener on the root element
// the document node could also be used but prefer using a less busy node
document.documentElement.addEventListener('click',

    function(event) {

        // the target element (button) of the clcik event
        var element = event.target;

        // skip processing elements that are not buttons or
        // buttons that do not have the specified className
        if (/^button$/i.test(element.nodeName) &&
            /(^|\s)square-btn(\s|$)/i.test(element.className)) {

            var $this = $(element);

            // Split name into array (e.g. "find_355" == ["find", "355"])
            var arr = $this.attr('name').split('_');

            // Toggle active class
            $this.toggleClass("active");
            if ($this.siblings().hasClass("active")) {
              $this.siblings().removeClass("active")
            }

            // Remove any existing instances of the filter from hidden form
            $('#tmpFilters input[value="exclude_'+arr[1]+'"]').remove();
            $('#tmpFilters input[value="find_'+arr[1]+'"]').remove();

            // If a filter has been applied then add it to hidden form
            if ($this.hasClass('active')) {
              $('#tmpFilters').append('<input type="hidden" name="tmpFilter[]" value="'+$this.attr('name')+'">');
            }

            // log info to the console, added as debug aid for the example code
            console.log('Clicked +/- button', arr,
                ($this.hasClass('include') ? 'button include' : 'button exclude'),
                ($this.hasClass('active' ) ? 'is "active"' : 'is not "active"'));
        }
    // true to select the event capturing phase, this is the fastest available event hook
    // events originates here first before drilling down to the target & bubbling back up
    }, true
);

function getAjaxFilters() {

    $('#ajaxContent').html('Reloading filters ...');
  
    $.ajax({
        url: $('#searchRegulations').attr('action'),
        // changed from 'post' to 'get'
        // only for the example code pen
        type: 'get',
        cache: false,
        data: $('#searchRegulations').serialize()
    }).done(function (response, status, xhr) {
        if (response) {
            $('main .content').hide();
            $('#ajaxContent').html(response).show();
            console.log('search_regulations filters reloaded');
            return false;
        }
    });

}
              
            
!
999px

Console