[html] How to apply a CSS class on hover to dynamically generated submit buttons?

I have the following piece of HTML/CSS code which is used to display pages based on the number of rows retrieved from a database.

_x000D_
_x000D_
.paginate {_x000D_
    font-family:Arial,Helvetica,sans-serif;_x000D_
    padding:3px;_x000D_
    margin:3px;_x000D_
}_x000D_
_x000D_
.disableCurrentPage {_x000D_
    font-weight:bold;_x000D_
    background-color:#999;color:#FFF; _x000D_
    border:1px solid #999;_x000D_
    text-decoration:none;color:#FFF;_x000D_
    font-weight:bold;_x000D_
}_x000D_
_x000D_
.paging {_x000D_
    cursor: pointer; _x000D_
    background-color: transparent;border:1px solid #999;_x000D_
    text-decoration:none;_x000D_
    color:#9CC;_x000D_
    font-weight:bold;_x000D_
}
_x000D_
<div class='paginate'>_x000D_
    <input type="submit" name="btnFirst" value="First" _x000D_
           class="disableCurrentPage" disabled="disabled"/>_x000D_
    <input type="submit" name="btnPrev" value="Previous" class="paging"/>_x000D_
        _x000D_
    <input type="submit" name="btnPage" value="1"_x000D_
           class="disableCurrentPage" disabled="disabled"/>_x000D_
    <input type="submit" name="btnPage" value="2" class="paging"/>_x000D_
    <input type="submit" name="btnPage" value="3" class="paging"/>_x000D_
    <input type="submit" name="btnPage" value="4" class="paging"/>_x000D_
    <input type="submit" name="btnPage" value="5" class="paging"/>_x000D_
    <input type="submit" name="btnPage" value="6" class="paging"/>_x000D_
    <input type="submit" name="btnPage" value="7" class="paging"/>_x000D_
    <input type="submit" name="btnPage" value="8" class="paging"/>_x000D_
    <input type="submit" name="btnPage" value="9" class="paging"/>_x000D_
    <input type="submit" name="btnPage" value="10" class="paging"/>_x000D_
        _x000D_
    <input type="submit" name="btnNext" value="Next" class="paging"/>_x000D_
    <input type="submit" name="btnLast" value="Last" class="paging"/>_x000D_
</div>
_x000D_
_x000D_
_x000D_

Upto this there is no question. I want to apply the CSS class something like the following to all of those buttons on mouse hover.

.button:hover {
    border:1px solid #999;
    color:#000;
}

Those buttons with the name attribute btnPage are generated dynamically in a loop. Therefore, I think it is inconvenient to apply the preceding CSS class based on the id attribute.

So, how can this class be applied to those buttons on hover?

This question is related to html css hover mousehover

The answer is


You have two options:

  1. Extend your .paging class definition:

    .paging:hover {
        border:1px solid #999;
        color:#000;
    }
    
  2. Use the DOM hierarchy to apply the CSS style:

    div.paginate input:hover {
        border:1px solid #999;
        color:#000;
    }
    

The most efficient selector you can use is an attribute selector.

 input[name="btnPage"]:hover {/*your css here*/}

Here's a live demo: http://tinkerbin.com/3G6B93Cb


Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to css

need to add a class to an element Using Lato fonts in my css (@font-face) Please help me convert this script to a simple image slider Why there is this "clear" class before footer? How to set width of mat-table column in angular? Center content vertically on Vuetify bootstrap 4 file input doesn't show the file name Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width

Examples related to hover

Angular 2 Hover event How can I access a hover state in reactjs? CSS disable hover effect How to remove/ignore :hover css style on touch devices Spin or rotate an image on hover How to make in CSS an overlay over an image? How to display and hide a div with CSS? simple Jquery hover enlarge Changing image on hover with CSS/HTML CSS On hover show another element

Examples related to mousehover

How to apply a CSS class on hover to dynamically generated submit buttons?