How do I bind functions to all input elements using jQuery?
Posted
by bakkelun
on Stack Overflow
See other posts from Stack Overflow
or by bakkelun
Published on 2010-03-23T08:50:19Z
Indexed on
2010/03/23
8:53 UTC
Read the original article
Hit count: 176
Hi,
let's say I have this set of HTML-markup and CSS
#CSS
.inputhelp_text { background: #000; color: #fff; }
.nodisplay { display: none; }
<input class="inputhelp" id="firstname" /><span class="inputhelp_text nodisplay" id="help_firstname">Write in your firstname</span>
<input class="inputhelp" id="lastname" /><span class="inputhelp_text nodisplay" id="help_lastname">Write in your lastname</span>
Using jQuery, I need to bind a function to all input fields (I guess using jQuery's EACH function) so that when I click the input field, it should switch the class of each span to only "inputhelp_text". I've gotten this to work in two separate functions for each field, but since I have alot of fields, I know there's a better way to solve it.
Any suggestions?
© Stack Overflow or respective owner