Intro.js: If Element does not exist.

Created on 22 May 2014  路  5Comments  路  Source: usablica/intro.js

So currently I have a bunch of elements that pops up on a page. Sometimes one of those elements wouldn't exist. IntroJs still display the text for that missing element. Is there a way I can just skip the element that does not exist and go straight to the next one?

Does that makes sense?

Thanks much
Stephen.

Most helpful comment

Awesome thank you for all your help!

I found another way here it is.


var intro = introJs();
          intro.setOptions({
            skipLabel: 'Exit',
            nextLabel: 'Next',
            prevLabel: 'Previous',
            showBullets: false,
            steps: [
              {
                element: '#IDTarget1',
                intro: "Text goes here 1",
              },
              {
                element: '#IDTarget2',
                intro: "Text goes here 2",
              },
              {
                element: '#IDTarget3',
                intro: "Text goes here 3",
              }
            ].filter(function(obj) { return $(obj.element).length; });
          });

I did a search for introJS().onbeforechange(function(targetElement) in google and found this gem.

http://stackoverflow.com/questions/21142183/ignore-missing-element-for-the-tour-in-tour-js/21142387#21142387

This fixed it!

All 5 comments

You might be able to achieve that by using introJs.onbeforechange. It is triggered on a new step, so you can check if your element exists, and if it doesn't, go to the next step?

So I have the following script:


var intro = introJs();
          intro.setOptions({
            skipLabel: 'Exit',
            nextLabel: 'Next',
            prevLabel: 'Previous',
            showBullets: false,
            steps: [
              {
                element: '#IDTarget1',
                intro: "Text goes here 1",
              },
              {
                element: '#IDTarget2',
                intro: "Text goes here 2",
              },
              {
                element: '#IDTarget3',
                intro: "Text goes here 3",
              }
            ]
          });

If "#IDTarget2" does not exist I would like for it to go to "#IDTarget3" when I click "Next" after "#IDTarget1". Correct me if i'm wrong, but, using introJs.onbeforechange() is based on if I knew which ID is missing correct? Because I wouldn't know if the ID is there or not.

Thanks again
Stephen

You are correct, except you can figure out if an ID is missing in onbeforechange, try this:

introJs().onbeforechange(function(targetElement) {  
  if (!targetElement) // if targetElement does not exist
    introJS().nextStep() // go to the next step
});

Awesome thank you for all your help!

I found another way here it is.


var intro = introJs();
          intro.setOptions({
            skipLabel: 'Exit',
            nextLabel: 'Next',
            prevLabel: 'Previous',
            showBullets: false,
            steps: [
              {
                element: '#IDTarget1',
                intro: "Text goes here 1",
              },
              {
                element: '#IDTarget2',
                intro: "Text goes here 2",
              },
              {
                element: '#IDTarget3',
                intro: "Text goes here 3",
              }
            ].filter(function(obj) { return $(obj.element).length; });
          });

I did a search for introJS().onbeforechange(function(targetElement) in google and found this gem.

http://stackoverflow.com/questions/21142183/ignore-missing-element-for-the-tour-in-tour-js/21142387#21142387

This fixed it!

oh cool fix! :+1: My pleasure

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hakib picture hakib  路  4Comments

litan1106 picture litan1106  路  3Comments

zombiezlk picture zombiezlk  路  6Comments

alexandernst picture alexandernst  路  5Comments

jaesung2061 picture jaesung2061  路  9Comments