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.
The event.preventDefault() method stops the default action of an element from happening. For example, Prevents a link from following the URL.
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.
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.
Using jQuery “.stop()” method we can stop the currently running 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.
The .animate() method allows us to create animation effects on any numeric CSS property. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect.
- styles: Specifies one or more CSS properties/values toanimate.
- duration: Optional. Specifies the speed of the animation.
- easing: Optional. Specifies the speed of the element in different points of the animation. Default value is “swing”.
- callback: Optional. A function to be executed after the animation completes.
Simple use of animate function is,
Hide Copy Code
eq() returns the element as a jQuery object. This method constructs a new jQuery object from one element within that set and returns it. That means that you can use jQuery functions on it.
get() return a DOM element. The method retrieve the DOM elements matched by the jQuery object. But as it is a DOM element and it is not a jQuery-wrapped object. So jQuery functions can’t be used.
The basic difference is the parent() function travels only one level in the DOM tree, where parents() function search through the whole DOM tree.
$(‘<div/>’) : This creates a new div element. However this is not added to DOM tree unless you don’t append it to any DOM element.
$(‘div’) : This selects all the div element present on the page.