Using jQuery one() method. This attaches a handler to an event for the element. The handler is executed at most once per element. In simple terms, the attached function will be called only once.
Tag Archives: PHP
jQuery Difference Between event.stopPropagation And event.stopImmediatePropagation
event.stopPropagation() allows other handlers on the same element to be executed, while event.stopImmediatePropagation() prevents every event from running. For example, see below jQuery code block.
$(“p”).click(function(event){
event.stopImmediatePropagation();
});
$(“p”).click(function(event){
// This function won’t be executed
$(this).css(“background-color”, “#f00”);
});
If event.stopPropagation was used in previous example, then the next click event on p element which changes the css will fire, but in case event.stopImmediatePropagation(), the next p click event will not fire.
jQuery Difference Between event.PreventDefault and “return false”
e.preventDefault() will prevent the default event from occurring, e.stopPropagation() will prevent the event from bubbling up and return false will do both.
jQuery event.stopPropagation
event.stopPropagation(): Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
For example, if there is a link with a click method attached inside of a DIV or FORM that also has a click method attached, it will prevent the DIV or FORM click method from firing.
jQuery Difference Between event.PreventDefault And event.stopPropagation
event.preventDefault(): Stops the default action of an element from happening.
event.stopPropagation(): Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
For example, if there is a link with a click method attached inside of a DIV or FORM that also has a click method attached, it will prevent the DIV or FORM click method from firing.
jQuery event.PreventDefault
The event.preventDefault() method stops the default action of an element from happening. For example, Prevents a link from following the URL.
jQuery Difference Between prop() and Attr()
attr(): Get the value of an attribute for the first element in the set of matched elements. Whereas,.prop(): (Introduced in jQuery 1.6) Get the value of a property for the first element in the set of matched elements.
Attributes carry additional information about an HTML element and come in name=”value” pairs. Where Property is a representation of an attribute in the HTML DOM tree. once the browser parse your HTML code ,corresponding DOM node will be created which is an object thus having properties.
.attr() gives you the value of element as it was defined in the html on page load. It is always recommended to use .prop() to get values of elements which is modified via javascript/jquery , as it gives you the original value of an element’s current state.
jQuery Create Clone Of An Object
jQuery provides clone() method which performs a deep copy of the set of matched elements, meaning that it copies the matched elements as well as all of their descendant elements and text nodes.
jQuery Stop Currently-running Animation
Using jQuery “.stop()” method we can stop the currently running animation.
jQuery Disable Animation
Using jQuery property “jQuery.fx.off”, which when set to true, disables all the jQuery animation. When this is done, all animation methods will immediately set elements to their final state when called, rather than displaying an effect.