jQuery > Selectors

Button selector in jQuery

How to select all buttons of the web page?


To select all buttons of the web page, we can use button selector ":button". It is done irrespective of whether input type="button" is used to button element is used to render buttons.

    <input type="button" value="Test" />
    <input id="txtName" type="text" />
    <input type="submit" value="Test" />
    
    <button id="button1">This is a button</button>

    <script>
        $(function () {
            $(":button").css("border", "2px dashed green");
        });
    </script>

Notice that in the above code snippet, we have two buttons. The first element render button with the help of  "input type='button' and 4th element render button with the help of "button" element. As this selector is especially to select all butons, it select both buttons and apply border style.

Output

Button selector

 Views: 8538 | Post Order: 24



Write for us






Hosting Recommendations