How to change maxlength attributes for all classes with name field answer

I have a class named "field answer" which has an attribute "maxlength" of 250. I want to change this to 9999 for each occurrence of this maxlength attribute.

<div class="field answer">
   <textarea name="ctl00$Main$ctrl_16161" rows="2" cols="20" id="ctl00_Main_ctrl_16161" class="long" 
    onkeyup="return cw.Utilities.trimLength(this)" maxlength="250" style="resize: none; height: 61px; 
    overflow-y: hidden;"></textarea>
</div>

I am a total noob when it comes to this so please understand. I’ve tried the following but no luck.

var fieldAnswer = document.getElementsByClassName("field answer");
if (fieldAnswer.namedItem = "maxlength") {
  fieldAnswer.maxlength = 9999;

The only thing that seems to work is when I call each tag individually like the following:

$(function() {
$("#ctl00_Main_ctrl_16161").attr("maxlength",9999);});

77 thoughts on “How to change maxlength attributes for all classes with name field answer”

Leave a Comment