By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Leave input:hover active if input has focus


Active Coder
Hey, I have an input field

.search-form input[type="text"]

and it is hidden until the following :hover css

.search-slide {
        left: -9999px;
        position: absolute;
        top: -9999px;
        white-space: nowrap;
        .search-form:hover .search-slide {
            left: auto;
            right: 100%;
            top: 0;

But I want to have it so if you enter text in the input, the :hover style stays visible so the input field doesn't disappear. Is there a simple way to code something like this with jQuery?
Hi wyclef,

If the search-form is hovered AND/OR if the 'search-slide' is focused:
.search-form:hover .search-slide, .search-form search-slide:focus{
    left: auto;
    right: 100%;
    top: 0;
That isn’t working for me. If I do something like this the .on state functions but when I click off it doesn't work. What am I missing here?

// search input focus
jQuery('#search-form').on('click', function searchInputFocus(event) {
    $(".search-slide").css({ "left": "auto", "right": "100%", "top": "0" });

jQuery('#search-form').off('click', function searchInputFocusOff(event) {
    $(".search-slide").css({ "left": "-9999px", "position": "absolute", "top": "-9999px" });

New Threads

Buy us a coffee!

Top Bottom