0

Am trying to remove "error-border" class for input fields in my form. i need to done it with javascript without using jquery, in 'Onfocus event' of each input field. Please help me to solve this

I have tried following code

document.getElementsByClassName("error-class").focus({
document.getElementsByClassName("error-class").remove();
});

Please help me to solve this

deceze
  • 471,072
  • 76
  • 664
  • 811
MCOPI
  • 21
  • 1
  • 4
  • See the linked question's answers and [basic event handling](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener). You might also look into [event delegation](https://stackoverflow.com/a/1688293/157247). – T.J. Crowder Apr 01 '19 at 09:35
  • `document.querySelector('input[type="text"]').addEventListener('focus', function(event) { this.classList.remove("error-class"); });` – mtx Apr 01 '19 at 09:44
  • I wasn't entirely happy with the delegation answers there, so [I added one](https://stackoverflow.com/a/55452921/157247). – T.J. Crowder Apr 01 '19 at 10:27

1 Answers1

0

Do it like this.

var error = document.getElementsByClassName("error-class");

error.onfocus = function(){
  error.classList.remove('error-class');
}
Thanveer Shah
  • 2,480
  • 2
  • 9
  • 20