We begin the cycles of lamer and small notes on working with jQuery.

Even up to this point, occasionally, it was necessary to use the clone() function of cloning objects in the code of small scripts. For example, a string like

$('.mob-sidebar').html($('aside').clone());

implemented cloning of the aside element inside the element with the mob-sidebar class. However, today I encountered the following problem - when cloning an element containing faceted filters, the checkboxes of these filters stopped working, while the active elements next to the checkboxes worked as they should.

The solution was to move the block with checkboxes, rather than cloning it, using the appendTo function

$("aside").appendTo(".mob-sidebar");

and unlike cloning, we first set the element to be moved, and then we specify the class of the element where we need to move it.

Below I will give just an example of use, where cloning and moving is done by clicking on an element with a specific ID

(function($){
	$(document).ready(function() {
		$('#menu-mob').click(function() {
			$('.mob-sidebar-filter').html($('aside').clone());
		});
	});
})(jQuery);
(function($){
	$(document).ready(function() {
		$('#menu-mob').click(function() {
			$("aside").appendTo(".mob-sidebar-filter");
		});
	});
})(jQuery);
Tags