Hiding text input placeholder that has two styles when input field is entered
I have a form with a placeholder that contains two styles. On keyup, the placeholder text will disappear, but how can I make it disappear when the user enters the text input field, either by tabbing into the field or by clicking into the field? Here's what I have. I included a Fiddle as well:
- <div class="container test">
- <div class="row">
- <div class="col-sm-12">
- <div class="placeholder-above"></div>
- <div class="guitar-service-address">
- <span class="placeholder-location"><span class="placeholder-float">Find guitar repair specialist. </span><span class="font-alt">Enter your guitar make and model...</span></span>
- <input id="input" type="text" />
- </div>
- <p class="help-block">What is this?</p>
- </div>
- </div>
- </div>
- $(function() {
- $("span.placeholder-location + input").keyup(function() {
- if($(this).val().length) {
- $(this).prev('span.placeholder-location').hide();
- } else {
- $(this).prev('span.placeholder-location').show();
- }
- });
- $("span.placeholder-location").click(function() {
- $(this).next().focus();
- });
- });
- if ($(window).width() < 768) {
- $(".placeholder-above").append( $(".placeholder-float").text() );
- }
- .container {
- max-width: 990px;
- }
- .tab-placeholder {
- display: none;
- }
- input[id="input"] {
- width: 500px;
- }
- .guitar-service-address>span.placeholder-location {
- position: absolute;
- margin: 6px 8px;
- color: #686e74;
- cursor: auto;
- font: Helvetica 15px/20px bold;
- font-weight: bold;
- z-index: 1;
- }
- .guitar-service-address>.placeholder-location>.font-alt {
- color: #686e74;
- font-weight: normal;
- }
- input {
- padding: 5px;
- font-size: 11pt;
- color: black;
- border: 1px solid #979797;
- border-bottom: 4px solid #000;
- }
- .help-block {
- font-size: 90%;
- }
- .test {
- padding: 20px;
- }
- @media (max-width: 768px) {
- input[id="input"] {
- width: 300px;
- }
- span > .placeholder-float {
- display: none;
- }
- .tab-placeholder {
- display: block;
- }
- }
http://jsfiddle.net/Codewalker/6or8pwjx/46/