Below is the PHP code to make Genesis search form input box text disappear on focus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('wp_enqueue_scripts', 'prefix_clear_search_form_input_box'); | |
function prefix_clear_search_form_input_box() { | |
wp_enqueue_script('clear-search-form', get_stylesheet_directory_uri() . '/js/clear-search-form.js', array('jquery'), '1.0.0', true); | |
} |
Below is the JS code to make Genesis search form input box text disappear on focus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
$('input').focusin(function() { | |
input = $(this); | |
input.data('place-holder-text', input.attr('placeholder')) | |
input.attr('placeholder', ''); | |
}); | |
$('input').focusout(function() { | |
input = $(this); | |
input.attr('placeholder', input.data('place-holder-text')); | |
}); | |
}); |
A much simpler (but less robust) method to make Genesis search form input box text disappear on focus is to use CSS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input:focus::-webkit-input-placeholder { color:transparent; } | |
input:focus:-moz-placeholder { color:transparent; } /* Firefox 18- */ | |
input:focus::-moz-placeholder { color:transparent; } /* Firefox 19+ */ | |
input:focus:-ms-input-placeholder { color:transparent; } /* oldIE ;) */ |