How to add more value to existing class (wordpress)?

Viewed 59

I need to add 'wsqmylogin' to existing class.
I trired the following codes, but they all don't add it.
Would you please let me know how to solve this problem?

Existing Code (created by plugin YITH):

<form id="yith-ywraq-default-form">
     <p class="form-row " id="message_field" data-priority="">
          <textarea name="message" class="input-text " id="message" placeholder=""></textarea>
    </p>
</form>


I tried:

jQuery('#yith-ywraq-default-form #message_field textarea[class="input-text"]').each(function()
{ this.setAttribute('class', 'wsqmylogin'); });

jQuery("#yith-ywraq-default-form #message_field textarea").prop("classs","wsqmylogin");

jQuery("#yith-ywraq-default-form #message_field  .input-text").prop("wsqmylogin")

Thank you.

1 Answers
  1. Dont use - in your class name.
  2. id must be unique so dont use id when iterate over each text box. Use class.
  3. If you have only 1 textarea no need to iterate, just catch DOM element and apply your css.
  4. setAttribute replace your whole previous class so if you want to add new class just use addClass

jQuery('#yith-ywraq-default-form .form-row textarea[class="inputtext"]').each(function() {
  this.setAttribute('class', 'inputtext wsqmylogin');
  //jQuery(this).addClass('inputtext wsqmylogin');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="yith-ywraq-default-form">
  <p class="form-row" id="message_field" data-priority="">
    <textarea name="message" class="inputtext" id="message" placeholder=""></textarea>
  </p>
</form>

Related