$(".info").html("") .innerHTML = "" . More preferred option: $(".info").empty() $(".info").html("").html("<b>Ok</b>") .html() will clear the element itself before inserting a new value..innerHTML . The fact is that inside the cleared element there can be such elements on which you previously hung up event handlers or anchored data using .data() . jQuery will clean this and there will be no memory leak. $(".info").remove() $("#history").css("display", "none") $("#description").css("display", "none") $("#category").css("display", "none") $("#contact").css("display", "none") $("#history, #description, #category, #contact").hide() .hide() to hide the element, and .hide() for showing.mouseenter/mouseleave vs mouseover/mouseoutmouseover/mouseout events on an element to display a pop-up hint, this hint is mouseover/mouseout . And this happens due to the fact that inside the element on which you hung handlers, is another element. When you hover the mouse cursor over it, the browser generates a mouseout event for your external element, and a mouseover event for the internal element, and then again a mouseover for the external element, which leads to a jitter.mouseenter/mouseleave , which solve this problem as follows. For the transferred handlers a certain wrapper becomes. At the moment when the cursor moves to the inner element, a mouseout event is mouseout for the outer element. At the same time, jQuery is not so naive and is not conducted on the machinations of the browser. The skeptical wrapper function checks the event.relatedTarget property — what the cursor is mouseleave at — and if it is inside an external element, it does not call the mouseleave handler that you mouseleave . And no flicker..hover(handlerIn, handlerOut) function .hover(handlerIn, handlerOut) , which accepts two handlers and hangs them like mouseenter and mouseleave : $(selector).hover(function() { tooltip.show() }, function() { tolltip.hide() }) .hover() is considered an obsolete function..parent() VS .closest() var person = $(".name").parent().parent().parent() $(".name") nestles in another place, but within the framework of the same person ? Many craftsmen call .parent() cyclically to the desired element..parentsUntil(selector) , which will return all parents to the specified one (excluding it). But still the decision is cumbersome: var person = $(".name").parentsUntil(".person").last().parent() var person = $(".name").closest(".person ") $.ajax() - less is better but better!$.ajax() . How much do you love him? In a previous article by another author cited the usefulness of working with this component. I'll bring a couple of my own ... $.ajaxSetup({ dataType: "json", url: "ajax.php", data: { user_id: userId } }); $.ajax({ data: { product_id: productId }, success: function(json) { console.log(json) }, alert: " ..." // ? . }) data parameters from $.ajaxSetup and $.ajax are glued together, and their sum is sent to the server (parameters from $.ajax overwrite the same from $.ajaxSetup ).$.ajax() - notify the user <div id="popup" class="---"></div> $("#popup").ajaxSend(function(event, xhr, options) { $(this).text(options.alert || "...").show() }).ajaxStop(function() { $(this).fadeOut("fast") }) .ajaxSend() calls the handler every time an AJAX request occurs. Here we display the transmitted (see above) message or the default message..ajaxStop() is called at the end, after all AJAX requests have been processed; those. if you have several AJAX requests processed in parallel, the handler will be called only once - after the execution of the last request. $("body").ajaxSend(function(event, xhr, options) { $('<div class="popup" />') .appendTo(this) .css({/* */}) .text(options.alert || "...") .delay(2000) // 2 .fadeOut("fast", function() { $(this).remove() }) }) $.ajax({ data: { action: "search-name", name: $("#name").val() }, beforeSend: function() { $(searchForm).trigger("start.search") }, complete: function() { $(searchForm).trigger("finish.search") } }) start.search and finish.search : $(searchForm) .on("start.search", function() { // }) .on("finish.search", function() { // }) Source: https://habr.com/ru/post/149349/
All Articles