Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How could I remove the ::after effect using JS?

I want to remove the ::after effect after a function is completed using JS.

Here is the code:

let text='Stack Overflow is a question and answer website for professional and enthusiast programmers. It is the flagship site of the Stack Exchange Network,[4][5][6] created in 2008 by Jeff Atwood and Joel Spolsky'
let interval;
let i =0;
interval=setInterval(function(){
                if(i<text.length){
                document.querySelector('div').textContent += text.charAt(i)
            }
            else{
                window.clearInterval(interval)
            }
            i++
            },20)
div::after{
   content:'|'
}
<div></div>

I just wonder if there is a way that I could remove the "|" (::after effect) after the interval finished.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks for any responds!

>Solution :

If you add a class to your definition, you can switch this one and off

div.foo::after{
content:’|’
}

setInterval(function(){
                if(i<text.length){
                document.querySelector('div').textContent += text.charAt(i)
            }
            else{
                window.clearInterval(interval)
                document.querySelector('div').classList.remove("foo");
            }
            i++
            },20)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading