• 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.
    • 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

wyclef

New Coder
Hey, I have an input field

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

and it is hidden until the following :hover css

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?
 

LTomy

Active Coder
Staff Team
Guardian
Hi wyclef,

If the search-form is hovered AND/OR if the 'search-slide' is focused:
CSS:
.search-form:hover .search-slide, .search-form search-slide:focus{
    left: auto;
    right: 100%;
    top: 0;
}
 

wyclef

New Coder
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?

JavaScript:
// 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" });
});
 

Top