              var elemName = elem.nodeName.toUpperCase();
              if (elemName === 'SELECT') {
                  elem.options[elem.options.length] = new Option(newRepr, newId, true, true);
              } else if (elemName === 'INPUT') {
                  if (elem.className.indexOf('vManyToManyRawIdAdminField') !== -1 && elem.value) {
                      elem.value += ',' + newId;
                  } else {
                      elem.value = newId;
                  }
              }
 
</s> remove         if (elem.className.indexOf('vManyToManyRawIdAdminField') !== -1 && elem.value) {
 </s> add         if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) { </s> remove                 if (inp.type === 'text' && inp.className.match(/vTimeField/)) {
 </s> add                 if (inp.type === 'text' && inp.classList.contains('vTimeField')) { </s> remove                 else if (inp.type === 'text' && inp.className.match(/vDateField/)) {
 </s> add                 else if (inp.type === 'text' && inp.classList.contains('vDateField')) { </s> remove         element.className += " type-active";
 </s> add         element.classList.add("type-active"); </s> remove                 if (elem.className.indexOf('active') !== -1) {
 </s> add                 if (elem.classList.contains('active')) {
                if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) {
              var elemName = elem.nodeName.toUpperCase();
              if (elemName === 'SELECT') {
                  elem.options[elem.options.length] = new Option(newRepr, newId, true, true);
              } else if (elemName === 'INPUT') {
                if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) {
                      elem.value += ',' + newId;
                  } else {
                      elem.value = newId;
                  }
              }
keep keep keep keep replace keep keep keep keep keep
 Fixed #31028 -- Used classList API to check, add and remove DOM classes.

Thanks to Claude Paroz for review. 
django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js