Title

jQuery most used actions

description

Some of (my) most used actions with jQuery, repeated here for copy and paste application

Published 2022-08-18

Modified 2022-08-19

content

				
					<!-- Same as above, shorthand opening of a script: -->
<script>
jQuery(function($) {
    // Code goes here
});
</script>


				
			
				
					$('.widget').addClass('active');
				
			
				
					$('.widget.active').removeClass('active');
				
			
				
					var widget = $('.widget');
var page = $('body');

if (widget.hasClass('active')){
    page.css('background-color','red');
 } else if (widget.hasClass('pending')){
    page.css('background-color','green');
 } else {
    page.css('background-color','green');
 }
				
			
				
					$('.trigger').click(function(){
    //
});
				
			
				
					$('.trigger').click(function(){
    $('.widget').toggleClass('active');
});
				
			
				
					$('.trigger').click(function(){
    $(this).toggleClass('active');
});
				
			
				
					var toggleVisibility = $('.widget');
var trigger = $('.trigger');
var toggleActive = $('.trigger, .widget');
    trigger.click(function(){
        toggleActive.toggleClass('active');
        toggleVisibility.slideToggle(400);
    }); 
// also .slideUp and .slideDown, .fadeToggle, .fadeIn and .fadeOut