How do I add legacy classes to the addClass

0

How can I add these classes?

.error textarea {
  border-color: red;
  border-width: 5px;
}

.error .counter {
  color: red;
}

to the addclass method, I'm trying this but it does not work for me

$("textarea").addClass("error textarea")

$("textarea").addClass("error counter")
    
asked by Oscar Diaz 13.09.2017 в 17:13
source

2 answers

0

The selectors that you are using, separated by a space, are to select elements textarea and counter that are INSIDE of another element with class error .

If you want to select items that contain both classes, delete the space:

.error.textarea {
  border-color: red;
  border-width: 5px;
}

.error.counter {
  color: red;
}
    
answered by 13.09.2017 / 17:31
source
0

You do not clearly understand what you want to do but if I understood correctly you could try this:

<div id="textarea">
    <textarea name="" id="" cols="30" rows="10"></textarea>
</div>
<script>
    $('#textarea').addClass('error');
</script>

There is no need to add textarea to the addClass () since when selecting the parent it looks for your child and applies the changes.

that's what you asked the CSS to do

.error textarea {...}

I hope it serves you.

    
answered by 13.09.2017 в 17:36