jQuery

Clear form fields with exception in jQuery

Share

Using jQuery you can clear form fields. Here I am going to describe, how we can clear all of the fields except a few using jQuery.

Example of Clear form fields:

 <div id="mainDiv">
 <input type="text" id="txt1" /><br/>
 <input type="text" id="txt2" /><br/>
 <input type="text" id="txt3" /><br/>
 <input type="text" id="txt4" /><br/>
 <button id="clearall">Clear All</button>
 </div>

Now, we can get this using a jQuery like below:

 $('#clearall').click(function(){
 $('#mainDiv > input:text').val('');
 });

Recent Posts

10 Reasons Why Technology is Good for Education

Educational technology has been very helpful in the era of ever-advancing technology. It opens millions…

15 hours ago

Chat GPT Login: Step-by-Step Guide for Beginners

Have you ever thought of a world where asking the Internet for information feels like…

19 hours ago

The Sharp-Looking Guy: 5 Essential Tips for Men to Become Sharp

We've gotten so used to seeing men streetwear joggers, ripped jeans, and sleeveless shirts. Hair…

2 days ago

How to Use Your Wedding Jewellery In Unique Ways At Festivals

When it comes to festivals, the options for wedding jewellery are endless. You can go…

2 days ago

5 Tips On Window Cleaning

Whether it concerns your home or an office building, the state of a property’s windows…

3 days ago

Sustainable Business Practices: A Win-Win Strategy

You know that running an environmentally sustainable business is the right thing to do. But…

3 days ago