Change DIV background color for all inputs in form
Posted
by
Erik
on Stack Overflow
See other posts from Stack Overflow
or by Erik
Published on 2012-04-09T17:25:48Z
Indexed on
2012/04/09
17:29 UTC
Read the original article
Hit count: 303
I have a form with 20 input fields.
Each input field is inside a DIV
I have a script that changes the background color of the DIV via keyup function along with two other DIV tags.
Rather than duplicating the script 20 times for each DIV and Input, is it possible to re-write the script to do all DIV's and their Inputs?
<script>
$(document).ready(function(){
$("#id").keyup(function() {
if($("#id").val().length > 0) $("#in1, #nu1, #lw1, #id").css("background-color",
"#2F2F2F").css("color", "#FFF");
else {
if($("#id").val().length == 0) $("#in1, #nu1, #lw1, #id").css("background-color",
"#E8E8E8").css("color", "#000");
}
});
});
</script>
© Stack Overflow or respective owner