Click here to Skip to main content
15,894,254 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a input:
HTML
<form id="integer" role="form" name="_form">
<div class="form-group">
                        <label>Amount</label>
                        <input type="number" name="Amount" class="form-control" placeholder="Enter amount">
                    </div>
</form>


Using a javascript function how can i change the
HTML
class="form-control"

For example when someone clicks submit?
Posted
Comments
ZurdoDev 23-Mar-15 8:46am    
First, put an ID on your div, it will make accessing it easier. Then just google for jquery add class and jquery remove class.

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Mar-15 9:12am    
5ed. I just added an answer with minor clarifications on jQuery.
—SA
In addition to Solution 2:

Class is just a part of DOM, which can be fully controlled by JavaScript. One simple way of doing such things is using jQuery. Please see:
http://api.jquery.com/addClass/[^],
http://api.jquery.com/removeClass/[^],
http://api.jquery.com/toggleClass/[^],
http://api.jquery.com/category/css[^].

If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com[^],
http://learn.jquery.com[^],
http://learn.jquery.com/using-jquery-core[^],
http://learn.jquery.com/about-jquery/how-jquery-works[^] (start from here).

—SA
 
Share this answer
 
v2
Comments
Peter Leow 23-Mar-15 10:00am    
Thank you, Sergey. 5ed.
Sergey Alexandrovich Kryukov 23-Mar-15 10:05am    
Thank you, Peter.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900