user715449
user715449

Reputation: 183

Jquery prev() dont work with input

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 () {
    $(this).prev("label").css("border-bottom", "1px dotted #63aec4");
  });

Upvotes: 0

Views: 254

Answers (5)

AEMLoviji
AEMLoviji

Reputation: 3257

look here please my fiddle
first you must close you label tag before adding input.

Upvotes: 1

Cristian
Cristian

Reputation: 327

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="" />

Upvotes: 3

ChrisThompson
ChrisThompson

Reputation: 2008

$(this).closest("label").css("border-bottom", "1px dotted #63aec4");

Upvotes: 0

Tomas Aschan
Tomas Aschan

Reputation: 60674

You're not looking for the element next to your <input> - you're looking for it's parent.

$(this).parent('label')...

Upvotes: 0

Calum
Calum

Reputation: 5316

$(this).parent("label").css("border-bottom", "1px dotted #63aec4");

Upvotes: 5

Related Questions