Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a text area?

How to disable a textarea which is dynamically added to the HTML?

HTML:

<div class="ss_datesel_inp_cont">
    <div class="ss_datesel_inp_right_corner">
    </div>
    <input autocomplete="off">
</div>

This is what I tried:

   $('.ss_datesel_inp_cont:textarea').prop("disabled", true);
   $('.ss_datesel_inp_cont:input').prop("disabled", true);
like image 576
jQuerybeast Avatar asked Oct 08 '11 03:10

jQuerybeast


People also ask

Can you disable a textarea?

When present, it specifies that the text area should be disabled. A disabled text area is unusable and the text is not selectable (cannot be copied). The disabled attribute can be set to keep a user from using the text area until some other condition has been met (like selecting a checkbox, etc.).

How do I restrict text area?

To set the width and height of the textarea of your own choice, you can specify the desired number of rows and columns. For this, we can make use of rows and cols attributes of <textarea> tag.

How do I GREY out textarea?

To prevent users from being able to modify a value in an <input> or <textarea> , you can use the disabled or readonly attributes. Browsers support an HTML attribute called disabled that will usually "gray out" the input and make it non-editable.


1 Answers

I don't see a textarea element in the code you posted? Based on the markup you have, you would disable the input by:

$('.ss_datesel_inp_cont input').prop('disabled', true);

The reason your code isn't working is simply because the selector is wrong. The input is a descendant of .ss_datesel_inp_cont and therefore you need to indicate that with a space between .ss_datesel_inp_cont and input. The input is also a direct child, so alternatively you could use the direct child token > as in $('.ss_datesel_inp_cont > input').

like image 89
jbyrd Avatar answered Sep 21 '22 06:09

jbyrd