I have the following code that would like to have a generic function for if possible. When needs to happen is the label on top needs to change color. I have a color gradient behind it so I need to use transparent PNG for the corners. The layout width needs to be liquid so I can’t really change the HTML too much.`
<div class="inputBody">
<div class="inputtop"><span class="inputtoptext">Username</span></div>
<div><input type="text" size="25"></div>`
</div>
<script>
$('input').focus(function() {
$(this).addClass("yellowinput");
});
$('input').blur(function() {
$(this).removeClass("yellowinput");
});
</script>
`
You can make one piece of code that works on a unit like this. All relevant id values are changed to class names and the whole piece is put into a container. That lets us find the object associated with this input container in a generic way relative to the object that caused the event.
FYI, a different approach could be done with a lot less code and using mostly CSS rules like this:
Then, you would just make all your CSS rules contingent upon whether an object has a parent CSS class
.hasFocusor not. The images would have to change to be background images, but they can even be done in CSS too.