Skip to main content.

Duplicate classes

Hide duplicates

var hidemask = document.querySelectorAll(".yourclass");

for (var i = 1; i < hidemask.length; i++) {
    hidemask[i].style.display = "none";
}

Remove duplicates

var hidemask = document.querySelectorAll(".yourclass");

for (var i = 1; i < hidemask.length; i++) {
    hidemask[i].remove();
}

Add a class to first instance

Example: slides and tabs

This example adds an active class to first instance of slide and tab in t4 hierarchy. This will be the first slide/tab to be viewed when you land on a page. This allows for more versatility in regards to mirroring and expiring etc.

$(function() {
	$(".tab-pane:first, .carousel-inner .item:first").addClass("active")
})

Alpha

<script>
//
//alpha 
//
$(document).ready(function() {
    $(".yourclass").append($(".yourclass .item").get().sort(function(a, b) {
        return parseInt($(a).attr("class").match(/\d+/)) - parseInt($(b).attr("class").match(/\d+/))
    }));
});
//
</script>

Replace string

Example: fix spacing from data

This example shows data coming in like Last,First Name with a fix to spacing changing to Last, First Name

// formatter code
<span class="fixSpace"></span>

// script
var $string = 'Last,First Name';
 $(".fixSpace").text($string.replace(/,/g, ", "));

Collapse All

<script>
$(document).ready(function() {

    setTimeout(function() {

        if ($('.course-page.btn-group').length) {

            $('.course-page.btn-group .collapse-all').hide();
            $('.course-page.btn-group .expand-all').on('click', function() {
                $('.course-page.btn-group ..accordion-block').addClass('active');
                $('.course-page.btn-group ..accordion-block>.accordion').addClass('active');
                $('.course-page.btn-group .button.excol').toggle();

                return false;
            });

            $('.course-page.btn-group .collapse-all').on('click', function() {
                $('.course-page.btn-group ..accordion-block').removeClass('active');
                $('.course-page.btn-group ..accordion-block>.accordion').removeClass('active');
                $('.course-page.btn-group .button.excol').toggle();

                return false;
            });


        } //end if .course-page.btn-group exists

    }, 500); // how long do you want the delay to be? 

}); //end doc ready

if ($('.course-info').length) {
    $('.collapse-all').hide();
    $('.expand-all').on('click', function() {
        $('.accordion').addClass('active');
        $('.accordion-block .dropdown').addClass('show');
        $('.button.excol').toggle();
        return false;
    });

    $('.collapse-all').on('click', function() {
        $('.accordion').removeClass('active');
        $('.accordion-block .dropdown').removeClass('show');
        $('.button.excol').toggle();
        return false;
    });
}; //end check for existence
</script>
+