javascriptjquerycssformsinternet-explorer-6

How to apply a class to all button?


In one of my projects I have used input[type="button"] to apply a style to all the buttons. It works fine in all browsers except Internet Explorer 6. It doesn't style the buttons.

Is there a solution for this, like creating some class for the button and applying it to all buttons?

I want to apply that class to all buttons but not manually. I think it's possible to use jQuery for this, could you please help me with this?


Solution

  • I usually like not to use JavaScript for this, so I add class="text" for <input> elements that are of text type, class="button" for <input> elements that are of button type, and so on. Then I can match them with input.text etc.

    While you don't want to do it manually, I consider it better practice. If you still want to do it with jQuery, you do it like this:

    $('input:button').addClass('button');
    // Or to include <button> elements:
    $('button, input:button').addClass('button');
    
    // Text inputs:
    $('input:text').addClass('text');
    // And so on...