question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kills all JS if not all ID's are available in document

See original GitHub issue

Hello! First of all: I love vivus.js, thank you. I’m new to JS, and I ran into a problem with the setup. vivus.js is part of my global script.min.js. when all ID’s are available in the html document, everything works great. but when only a single ID that is requested by the instance is missing, or if none are available, it kills all javascript on the website. what am I missing? thank you very much.

Vivus Version: v0.4.2 Safari Browser: 11.0

index.html (no ID, kills all js)

<body>
    <div>
        Content
    </div>
<script src="/js/script.min.js"></script>
</body>

example.html (not all IDs, kills all js)

<body>
    <div>
        <svg id="mysvg1">
        </svg>
    </div>
<script src="/js/script.min.js"></script>
</body>

example2.html (all IDs, all js works)

<body>
    <div>
        <svg id="mysvg1">
        </svg>
    <div>
    </div>
        <svg id="mysvg2">
        </svg>
    </div>
<script src="/js/script.min.js"></script>
</body>

Set up

new Vivus('mysvg1', {duration: 200}, myCallback);
new Vivus('mysvg2', {duration: 200}, myCallback);

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
maxwellitocommented, Dec 24, 2017

As I said before, if the ID doesn’t exist, it will trigger an error.

So for each of your instances I would suggest you to test is the ID is available before running the code.

if (document.getElementById('mysvg1')) {
  new Vivus('mysvg1', {duration: 200}, myCallback);
}
if (document.getElementById('mysvg2')) {
  new Vivus('mysvg2', {duration: 200}, myCallback);
}

Also, make sure that myCallback exists if you plan to use it.

0reactions
maxwellitocommented, Dec 24, 2017

All güüd then 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Select all elements that don't start with a certain id
javascript - Select all elements that don't start with a certain id - Stack Overflow. Stack Overflow for Teams – Start collaborating and ......
Read more >
Backbone.js
Removes all attributes from the model, including the id attribute. Fires a "change" event unless silent is passed as an option. id model.id...
Read more >
Node.js v19.3.0 Documentation
Every .html document has a corresponding .json document. This is for IDEs and other utilities that consume the documentation.
Read more >
CDE :: Home
The FBI's Crime Data Explorer (CDE) aims to provide transparency, create easier access, and expand awareness of criminal, and noncriminal, law enforcement data ......
Read more >
Stripe JS Reference
This reference documents every object and method available in Stripe's browser-side JavaScript ... The form will render with empty fields if not provided....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found