I can´t change the css with prev, where is my mistake? Fiddlelink
Tanks for looking!
Css:
.i1 {
float: right;
height: 18px;
margin-top: 6px;
}
label {
border-bottom: 1px dotted #CCCCCC;
clear: both;
float: left;
height: 25px;
margin: 5px 0 0;
width: 450px;
line-height: 32px;
}
Html:
<label>Titel:<input class="i1" type="text" name="titel" value="" /></label>
<label>Vorname:<input class="i1" type="text" name="vorname" value="" /></label>
<label>Nachname:<input class="i1" type="text" name="nachname" value="" /></label>
Jquery:
$("input").focus(function () {
$(thi开发者_开发技巧s).prev("label").css("border-bottom", "1px dotted #63aec4");
});
$(this).parent("label").css("border-bottom", "1px dotted #63aec4");
That's because you putted everything into the label tag...try change the html like this:
<label for="titel">Titel:</label><input tabindex="1" class="i1" type="text" name="titel" value="" />
<label for="vorname">Vorname:</label><input class="i1" type="text" name="vorname" value="" />
<label for="nachname">Nachname:</label><input class="i1" type="text" name="nachname" value="" />
look here please
my fiddle
first you must close you label tag before adding input.
You're not looking for the element next to your <input>
- you're looking for it's parent.
$(this).parent('label')...
$(this).closest("label").css("border-bottom", "1px dotted #63aec4");
精彩评论