-2

Hi please help me out how can i target a specific element which is .typed::after using js ? the code below can only target classes without ::after or before and the cursor is on the after of typed

HTML

<span class="typed"></span>

JS

$(function(){
    $(".typed").typed({
        strings: ["the Philippines"],
        // Optionally use an HTML element to grab strings from (must wrap each string in a <p>)
        stringsElement: null,
        // typing speed
        typeSpeed: 40,
        // time before typing starts
        startDelay: 1200,
        // backspacing speed
        backSpeed: 20,
        // time before backspacing
        backDelay: 500,
        // loop
        loop: true,
        // false = infinite
        loopCount: 1,
        // show cursor
        showCursor: false,
        // character for cursor
        cursorChar: "|",
        // attribute to type (null == text)
        attr: null,
        // either html or text
        contentType: 'html',
        // call when done callback function
        callback: function() {
               $(".typed::after").hide();
        },


    });
});

3 Answers3

1

You cannot, but you can add a class to the .typed element that removes the :after by setting its content to none

callback: function() {
           $(".typed").addClass('finished');
    },

and

.typed.finished:after{content:none;}
Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
0

You can't target pseudo-elements with javascript, there are only a css thing.

What you should do is toggle a class on .typed that will itself hide the pseudo element.

Axnyff
  • 9,213
  • 4
  • 33
  • 37
0

Hi do check this example script i made to manipulate the pseudo-class

<style>
    .typed:after {
        content: 'foo';
    }
    .typed.hidden:after {
        display: none;
    }
</style>
<script>
    $('.typed').addClass('hidden');
</script> 

this is because content created by :after or :before is not part of the DOM and therefore cannot be selected or modified.

for more info refer to this question jQuery and hiding :after / :before pseudo classes

Oliver Ong
  • 97
  • 8