andru26
3/30/2017 - 9:31 PM

Dropdown jQuery

Dropdown jQuery

function toggleDropdown(){
	
	$("html").on("click", function(e){
		$(".dropdown, .simple_drop").removeClass("open").find("> .dropdown_content").slideUp(250);
	});	
	
	$(".dropdown, .simple_drop").on("click", function(event){
		event.stopPropagation();
	});
	
	$(".dropdown, .simple_drop").on("click", ".dropdown_title", function(){
		var drop = $(this);
		if(!drop.parent().hasClass("dont_close_others")){
			$(".dropdown.open, .simple_drop.open").not(drop.parent()).removeClass("open").find("> .dropdown_content").slideUp(250);
		}
		drop.parent().toggleClass("open").find("> .dropdown_content").slideToggle(250);
	}).on("click", ".close_dropdown, li", function(){
		var $this = $(this);
		if($this.closest(".dropdown_content").parent().hasClass("select_drop")){
			var clicked = $this.html();
			$this.closest(".dropdown_content").parent().find(".dropdown_text").empty().html(clicked);
			
		}
		$this.closest(".dropdown, .simple_drop").removeClass("open").find("> .dropdown_content").slideUp(250);
	});

}

toggleDropdown();