Diesel Posted April 1, 2005 Posted April 1, 2005 Anyone know how to access a label control (or whatever it is) through the control it is associated with? Example: <label for="email">Email Address</label> <input type="text" id="email" size="20" maxlength="50" /> I want to change the font color of the label associated with the control when the user leaves the control. Quote
kahlua001 Posted April 4, 2005 Posted April 4, 2005 <div id="div_email">Email Address</div> <input type="text" id="email" size="20" maxlength="50" onblur="change_color(this);"/> in JS, change the class of the div change_color(formobject) { var label_id = document.getElementById('div_' + formobject.id) label_id.class = 'highlighted'; { I forget the id attribute in JS, might be name? also, not sure about the css class attribute. Hope it helped. Quote
Diesel Posted April 4, 2005 Author Posted April 4, 2005 Thanks for the effort, though, I was specifically looking for a relationship reference between a label tag and a textbox control. Notice the label control in my example did not have an id. Accessing an element by assuming it has a certain id (div*) is cheap. I'm thinking there has to be something in the dom that references the textbox from the label tag, otherwise there would be no point for the 'for' attribute. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.