niloofar
niloofar

Reputation: 2334

How to keep focuse css style after clicking a button (the style disappears after clicking anywhere)

There is an input tag with type of submit in my script. How I can keep the focused css style after clicking that? The css style disappears after clicking anywhere on the webpage. I want the button to keeps its css style till I click on an other input.

Upvotes: 1

Views: 1156

Answers (2)

niloofar
niloofar

Reputation: 2334

Well with using :focus, the style will disappears after clicking anywhere on the web page.

I found an example myself, now after clicking a button, if I click anywhere on the web page, the button will keeps its style unless I click on an other button.

<input type="submit" id="first" value="first"><br>
<input type="submit" id="second" value="second">


<script>
$(document).ready(function(){
    $("#first").click(function(){
        $(this).css("background-color", "red");
        $("#second").css("background-color", "transparent");
    });
    $("#second").click(function(){
        $(this).css("background-color", "red");
        $("#first").css("background-color", "transparent");
    });
});
</script>

Upvotes: 0

Naga Sai A
Naga Sai A

Reputation: 10975

        input[type=submit]:focus {
            background-color: lightblue;
        }

codepen URL for reference- http://codepen.io/nagasai/pen/zBqGRK

Upvotes: 0

Related Questions