0

I want to trigger a CSS transition (fade-in message) in Javascript (using no framework) when there is an error. I added a trigger class to my div, but it doesn't fade in when the error pops up. Any ideas how I could fix this?

HTML file:

<div id="errorID" class="errorMessage">
    <strong>Error!</strong> Something went wrong.
</div>

Javascript file:

if (!valid){ // error -> errorTextMessage
    var errorBox = document.getElementsById('errorID');
    errorBox.classList.add("errorTrigger");
}

CSS file:

.errorMessage{
    padding: 20px;
    background-color: #f44336;
    color: white;
    opacity: 0;
    -webkit-transition: opacity 1s ease-in-out;
 }

.errorMessage.errorTrigger{
    zoom: 1;
    filter: alpha(opacity=50);
    opacity: 1;
}
2
  • 2
    there is a typo getElementsById should be getElementById Commented Mar 30, 2018 at 10:55
  • @Bhuwan Thank you man you saved my life! Didn't see that typo. Commented Mar 30, 2018 at 11:04

2 Answers 2

1

-webkit-transition is an experimental property that webkit-based browsers used (a long time ago) when testing their implementations of transition.

It should never be used in production and no modern browser supports it.

Use the real transition property.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the suggestion, I'm gonna use that from now on.
0

As @Bhuwan said, I had a typo at document.getElementById.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.