Search code examples
javascriptjquerytwitter-bootstrapdatetimepickerbootstrap-datetimepicker

How to apply Jquery to textbox, CssClass instead of ID in Jquery,Bootstrap


I am using one JQuery plugin which is giving me Calendar with Time selection on click of that textbox this plugin very flexible to use.

below is the code which I am referring to use this plugin.

   <link href="DateTimePicker/jquery.datetimepicker.css" rel="stylesheet" type="text/css" />
    <script src="DateTimePicker/jquery.js" type="text/javascript"></script>
    <script src="DateTimePicker/jquery.datetimepicker.full.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            $('#datetimepicker_mask').datetimepicker({
                mask: '9999/19/39 29:59'
            });

        });
    </script>
<h3>Mask DateTimePicker</h3>

<input type="text" value="" id="datetimepicker_mask"/><br><br>

Above code works fine for me for single Textbox.

but I have to use this plugin for more then one textbox so this I can use only if this plugin is taking by Class instaed of Id.

so I am not getting what change I have to do in the Jquery to achieve the task. there are so many Jquery & Css which is dependent on this.

Can anyone help me for this.


Solution

  • JQuery's selectors are very similar to CSS selectors. So you can use .class to select by class.

    In your example you would change your selector to

    $('.datetimepicker_mask')
    

    And use a class on your input instead of id

    <input type="text" value="" class="datetimepicker_mask"/>