Categories
jQuery

How to check checkbox with jQuery?

The correct way to check checkbox on the DOM elements can be done using jQuery .prop or .attr method. By using JavaScript’s “checked” property, we can solve the problem directly, instead of manipulating the DOM into doing what we want it to do. To check checkbox see the below script: After jQuery version 1.6 you […]

Categories
jQuery

jQuery Checkbox checked property

The checkbox checked property of a checkbox element gives you the checked state of the element. But you can also check using is() method. Example of Checkbox checked: <input type=”checkbox” id=”checkID”/> Then using checked property you can check this: if(document.getElementById(‘checkID’).checked){ // checked } else { // unchecked } Alternatively, you can use jQuery is() function […]

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
jQuery

Difference between jQuery’s replaceWith() and html()

The jQuery replaceWith() method replaces each element in the set of matched elements with a new content and return the set of elements that was removed. Lets discuss about the difference between replaceWith and html. Possible values: – HTML elements – jQuery objects – DOM elements But in jQuery html() it sets the HTML contents […]

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