Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
Remove border outline when key stroked with javscript or css

Can anyone point me in the right direction for my problem. I wrote a rule that will out line my input box when there is no value submitted. But now would like to remove the red outline when I start typing in the input box. Suggestions?

enter image description here

CSS

  .placeholder-red-text {
  border: 1px solid #ff0000 !important;
}

JS

return x.classList.add('placeholder-red-text');

HTML

<input id="red-border-error"></input>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use another attribute of your input to set the style, i can think of three simple examples:

1: Make the input required and check if the input is valid

.foo { outline: 2px }
.foo:valid { outline: 0 }

and in your html

<input class="foo" required>

2: Do the same with a data attribute and some js like this

const fooEl = document.querySelector('.foo')

fooEl.addEventListener('input', (e) => {
  fooEl.setAttribute('data-foo', e.target.value)
})
.foo {
  outline: 2px yellow solid;
}

.foo:not([data-foo=""]) {
  outline: 0;
}
<input type="text" class="foo" data-foo="">

3: Same as before but setting a new class, or just setting a boolean value for the data-attribute instead of the value..

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!