Skip to content

Initialization/stringsElement issue with HTML elements #622

@frzsombor

Description

@frzsombor

After reviewing the config properties and the code, I expected that it is possible to simply use a HTML element (as a variable) to initialize the library and also pass this element to the stringsElement config property to keep everything dynamic. However, it seems like typed.js can not use and animate an already existing element, as this is not working:

<!-- Element to contain animated typing -->
<span id="element">Hello world!</span>

<!-- Load library from the CDN -->
<script src="https://unpkg.com/[email protected]/dist/typed.umd.js"></script>

<!-- Setup and start animation! -->
<script>
  var el = document.getElementById('element');
  var typed = new Typed(el, {
    stringsElement: el,
    typeSpeed: 60
  });
</script>

I also really don't get it, why the following is not working either:

var el = document.getElementById('element');
var typed = new Typed(el, {
  strings: [ el.innerHTML ],
  typeSpeed: 60
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions