DO YOU NEED A CONTENT WRITER FOR YOUR BUSINESS?

Your One-Stop Solution for All Content Needs! Click here for more!
Categories: jQuery

Enable or disable an input field with jQuery

Share

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.

Disable a Control:

$( "#elementID" ).prop( "disabled", true );

Enable a Control:

$( "#elementID" ).prop( "disabled", false );

Also Read:

Using .attr():

Set the disabled attribute:

$("input").attr('disabled','disabled');

To enable again you can use .removeAttr():

$("input").removeAttr('disabled');

This will totally remove the disabled attribute from the element instead of blanking it out.

Read jQuery reference for more details.

Namaste UI

For any types of queries, you can contact us on info[at]namasteui.com.

Recent Posts

Writing Tools That Help Content Marketers Produce Cleaner Work

Content marketing has a hidden tax. It's not the writing itself, it's everything that happens…

2 weeks ago

How Data Analytics Is Actually Driving Smarter Marketing Decisions

Most marketing teams aren't failing because they lack data. They're failing because they can't act…

4 weeks ago

The Ultimate SPF Tester Guide: Boost Email Deliverability In Minutes

Email marketing continues to be one of the most effective ways for businesses to communicate,…

4 weeks ago

Sales Ops: A role that helps sales teams work as efficiently as possible

Xerox first introduced it around the mid-1970s. The need came up because the management activities…

1 month ago

Forex Investment Tips for Beginners

Investing in the forex market may look to be a dangerous game. With some worthwhile…

1 month ago

How Did The Restaurant Industry change In Post Pandemic Era?

The coronavirus outbreak has drastically changed the way we live our lives. Yes, that's absolutely…

2 months ago