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 […]

Categories
jQuery

jQuery :visible – Check for hidden elements in jQuery

The :visible selector check if an elements are hidden in jQuery by selecting each and every elements in a DOM that is currently visible or not. But visible elements are elements which are not: – set to display:none – width and height set to 0 – form elements with type=”hidden” – parent is set as […]

Categories
jQuery

jQuery one() Method

The jQuery one() Method attached a handler for the selected elements and executed at most once per element per event type. Using one() method, the event handler is only run ONCE for each element. Possible event values are: blur, load, focus, resize, unload, scroll, click etc. Syntax: This is the simple syntax for using this […]

Categories
MySQL

mysql_fetch_array() expects parameter 1 to be resource, boolean given

Trying to select data from a MySQL table, but getting the error messages: mysql_fetch_array() expects parameter 1 to be resource, boolean given? – This may happen for various reasons like both the mysql_* and the mysqli extension will return false from their query functions. – Using a die() you can get a little to much. […]

Categories
jQuery

How can I make a redirect page using jQuery?

Redirect one page to another page can be done via replace the location or change the href. But jQuery is not necessary for redirecting the page. It is better to use window.location.href = “http://www.namasteui.com”; Rather than window.location.replace(“http://www.namasteui.com”); as replace() does not put the originating page in the session history. But as it requires jQuery then […]

Categories
jQuery

jQuery serialize() function

jQuery serialize() method creates a URL encoded text string by serializing the form values. This values can be used in query string for making an AJAX request. jQuery serialize() can act on a jQuery object for selecting individual form controls like <input>, <textarea>, and <select> etc. Example of serialize: Suppose, you have a following HTML: […]

Categories
jQuery

jQuery serializeArray() key value pairs

jQuery serializeArray() creates an array of objects i.e. name and value pair by serializing one or more form elements or the form element itself. jQuery serializeArray() method can act on a jQuery object which has selected individual form controls like <input>, <textarea>, and <select> etc. Suppose, you have a following HTML: <form action=””> Name: <input […]

Categories
jQuery

Traversing Siblings

The jQuery  siblings() method returns all the sibling elements of the selected element. For example: $(“div”).siblings(); But if you want to filter the search for siblings then you can use an optional parameter. $(“div”).siblings(“p”); Read Also: Select an element with multiple classes in jQuery jQuery clone – create a deep copy of matched elements Suppose […]

Categories
jQuery

Difference between size and length of jQuery

jQuery .size() and .length both return the number of elements in the jQuery object. Size() and length in jQuery both returns the number of element in an object but length is faster than the size because length is a property and size is a method and length property does not have the overhead of a […]

Categories
jQuery

$.stop() vs. $.finish() in jQuery animations

jQuery stop and finish methods are used to end of all of the queued animations. jQuery stop() method stops the currently running animation on the matched elements but jQuery finish() stops the currently running animation, removes all the queued animations and complete all the animations for the matched elements. Let’s see what jQuery stop and finish […]