Apply CSS class to focused element with jQuery

See here for the original answer.

You just have to add separate ID's to access the different fields:

<span class="fakeplaceholder" id="first">First Name</span>
<span class="fakeplaceholder" id="last">Last Name</span>

Then apply the fakeplaceholdertop class to the specific element:

$(".firstname").focus(function() {
    $("#first").addClass("fakeplaceholdertop");
});

$(".lastname").focus(function() {
    $("#last").addClass("fakeplaceholdertop");
});

Tags

  1. jquery (Private)
  2. html (Private)
  3. focus (Private)
  4. stack-overflow (Private)
  5. answer (Private)