Adding Css class to all <input type'text'> elements? Javascript / Css?

Posted by Kohan on Stack Overflow See other posts from Stack Overflow or by Kohan
Published on 2010-05-14T16:59:20Z Indexed on 2010/05/14 17:04 UTC
Read the original article Hit count: 304

Filed under:
|
|

I want to apply a CSS class to every textbox in my site:

        <div class="editor-label">
            <label for="FoodType">FoodType</label>
        </div>
        <div class="editor-field">
            <input id="HelpText" name="FoodType" type="text" value="" />
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>

And I thought, Hey! Easy. I'll add a jquery function to find them all in the masterpage.

<script type="text/javascript">
    $(document).ready(function(){
        $('input').addClass('textbox');
    }
</script>

Unfortunately this will also select the submit button. How can i only select input elements that have a text type attribute?

Alternativly is this possible using entirely CSS?

If both these methods are not possible, i guess i will just have to manually add the class to every textbox i make?

Cheers, Kohan.

© Stack Overflow or respective owner

Related posts about css

Related posts about jQuery