I have a FIRST NAME and a LAST NAME text field. I want to display a line of text when either of them are focused and hide the line of text only when both elements are not focused.
My current code flips the text (hides then unhides) whenever I change focus from say the first name to the last.
I understand why, first name is getting blurred (triggering the hide animation) then last name gets the focus (triggering the show animation). This is undesirable for obvious reasons, I'm looking for an elegant fix.
HTML
<input type="text" placeholder="First" id="first" name="first" required>
<input type="text" placeholder="Last" id="last" name="last" required>
<p id="nameTxt" style="display: none">Blah blah blah</p>
Script
$('#first, #last').focus(function() { $("#nameTxt").show(300); });
$('#first, #last').blur(function() { $("#nameTxt").hide(150); });