Search code examples
htmlrecaptcharequired-field

Can I add the required attribute to an input field using css?


I have a recaptcha widget in my form and i want it to be made mandatory. since i dont have any direct control over the widget in my html, i was wondering if i can add the required attribute to it after it has been rendered.

ie. if i add the folloing css

#recaptcha_response_field{background-color:#000000;}

it does color up the recaptcha widget text field. in the same vein, if there was some way of setting the required="required" attribute for input fields via css, i'd be able to make it mandatory.


Solution

  • Does the following work for you:

    $(function() {
        $("#recaptcha_response_field").attr('required','required');
    });