Categories
jQuery

Enable or disable an input field with jQuery

Using jQuery prop() method you can enable or disable a form element. From jQuery 1.6+ you can use jQuery prop() method. You can enable or disable an elements on a page dynamically with jQuery by setting their attributes accordingly. For jQuery 1.5 and below the .prop() function doesn’t exist, but .attr() method does similar thing. […]

Categories
jQuery

Select an element with multiple classes in jQuery

The basic concept of jQuery is to select one or more elements using element ID, Class, Attribute, Compound CSS Selector and do something with them. Let’s see how to select an element with multiple classes. For simple selection you can use following code as below. Selecting Elements by ID: $( “#Id” ); Selecting Elements by […]

Categories
jQuery

Difference between jQuery.extend and jQuery.fn.extend

There is a significant difference between using jQuery extend() with passing one argument and doing it with two or more arguments. Basically, jQuery.extend() merge the contents of two or more objects into the first object. $.extend() is used to extend any object with additional functions but $.fn.extend() is used to extend the $.fn object, which […]

Categories
jQuery

Get selected text from drop down list in jQuery

jQuery select elements typically have two values which you want to access. First thing is that there is the value that you can get i.e. $( “#selectID” ).val(); And the second thing is the text value of the select box. Using the following select box you can get the text which is selected. Get selected […]

Categories
jQuery

jQuery clone – create a deep copy of matched elements

The jQuery clone() Method creates a deep run time copy of set of matched DOM Elements  to another location in the DOM elements and select the clones. This is very useful for run time copies of the elements to another location in the DOM elements. Syntax: $(selector).clone(true|false) true: specifies the event handlers which should be […]

Categories
jQuery

jQuery get() Method

jQuery get() method sends an HTTP GET request to a page load data from the server back. If any request with jQuery.get() method returns an error code then it will fail without notification unless the script has also called the global .ajaxError() method. In other side, as of jQuery 1.5, the .error() method of the […]

Categories
jQuery

How to disable jQuery animations

The jQuery.fx.off method is used to globally enable or disable jQuery animations whose default value is false which allows animations to run normally. Syntax: jQuery.fx.off = true|false; $.fx.off = true|false; The true value specifies that the animations should be disabled and the false value is default value which specifies that the animations should be enabled. […]

Categories
jQuery

Difference between prop and attr in jQuery

The prop and attr both method sets or returns properties/attributes and values of the selected elements. Let’s see the difference between Attr and Prop in jQuery. prop() grabs the specified DOM property whereas attr() grabs the specified HTML attribute. To know more about jQuery prop(), click here. To know more about jQuery attr(), click here. […]

Categories
jQuery

Add table row dynamically in jQuery

Want to add an additional row to a table as the last row in jQuery? Use jQuery after() method to add table row dynamically after last row. You can include anything within the after() method and this is a valid HTML, including multiple rows as per the example below: Example to add table row dynamically: […]

Categories
jQuery

Difference between event.preventDefault() and return false

preventDefault() prevents the default event from occuring, stopPropagation() prevents the event from bubbling up and return false does the both. Example of preventDefault() and return false: $(‘a’).click(function() { return false; }); $(‘a’).click(function(e) { e.preventDefault(); }); So finally, return false from within a jQuery event handler is effectively same as calling both e.preventDefault and e.stopPropagation on […]