How to check if an element has a class using jQuery / How to check the presence of a class on an element using jQuery

Overview

A web element may have an attribute class with some value. An example is <input type = "text" class = "myClass"/>. The value of class name may represent a CSS(Cascading Style Sheet) styling rule which will be applied on elements having this class such as .myClass{ background-color : blue} or it may be used to distinguish it from other elements which do not have this class.

(more…)

Continue Reading

How to highlight a table row on click using jQuery

Any element is highlighted due to its background-color property. By default this property has NO value, hence the element is not highlighted when it is at first added to the page.
If we change the value of this property, we are easily able to highlight the element. For highlighting an element (such as a table row) on click, there are a couple of approaches using jQuery:

I. Change the ‘background-color’ property of the row in the click event handler of the row. Code would be: (more…)

Continue Reading

Encoding (+) symbol in ajax request jQuery / jQuery ajax request removing (+) sign / How to send ‘+’ through AJAX post

Scenario

There may be a scenario where you are sending HTML form fields in ajax POST request or sending the value of a particular form field (let’s say input box) as a parameter in ajax request. For Example, suppose there is an input box on a web page with id “userName” and you send its value to the server in an ajax request as :

(more…)

Continue Reading

How to capture an element in jQuery / Locating element in jQuery

Capturing an element of a web page means to get a reference to an element (or simply getting the element) so that actions may be performed over the element. Actions cover hiding / showing the element, removing it from the page, getting its value, getting its text, modifying its value / text etc. Examples of elements on a web page are text box, button, drop down, checkbox, radio button, span, div etc.

There are 4 ways to get an element in jQuery: (more…)

Continue Reading

How to send form data to Spring controller using ajax / How to Submit Form using ajax

There are scenarios where you want to silently post a form to server or submit a form without a page refresh. Typical example is a Facebook page where you comment on a post. When you comment, the page is not refreshed but the comment is saved somewhere on the server which means that a save request is sent without entire page submit.
This involves the use of ajax. As soon as we decide to use ajax, a question arises as to how we would send form data from jsp to server without page submit and there would be a big hassle involved in form data transmission. Well!!! After reading this post, you won’t feel the same. (more…)

Continue Reading
Close Menu