Skip to main content
Known Participant
June 9, 2022
Answered

Check if object is hidden or showing with javascript

  • June 9, 2022
  • 4 replies
  • 1023 views

Hi all.

I'm wondering if anyone knows of a way to check if an object in captivate is hidden or showing, using javascript?

I know I can show/hide using cp.show(objId);

But I want to check if an object is already showing or hiding.

 

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    You can do it with this script:

     

    cp.model.data.SmartShape_2c.effectiveVi;

     

    The bold text is the name of the element you want to check. You must append the "c" to the name of the element.

    4 replies

    Known Participant
    June 10, 2022

    Thanks for the replies.

    It's not that easy javascripting when there is no place to look up available variables and functions.

    Just thought I'd post the output of my tests. 

    Context: I'm making templates, and in this assignment, there wil at the end appear max 4 buttons (click here to learn more about this type buttons). It's built so the page can be duplicated, and you can change the content, but all functonality will stay the same. When we use the template, I decided to simply turn of the visibility of the buttons we are not to use. So now I can loop through the buttons, check the visibility and only show/activate the buttons that were visible from start.

     

    //Get all the response-buttons - I know there is max 4 and that their name/ID begins with "analyze_RespBtn_"
    var analyze_allRespBtns = document.querySelectorAll("[id^='analyze_RespBtn_']");

     

    //Just to test – Check the visibility of the first object in the node list (it's the canvas-object)
    var justTesting1 = cp.model.data[analyze_allRespBtns[0].id].effectiveVi;
    var justTesting2 = cp.D[analyze_allRespBtns[0].id ].visible;

     

    Output if object is not visible:
    justTesting1 = 0
    justTesting2 = true

     

    Output if object is visible:
    justTesting1 = 1
    justTesting2 = 1

    TLCMediaDesign
    Inspiring
    June 10, 2022

    The difference between mine and StagPrimes is that "effectiveVi" will show the actual visibility. If the element is hidden initially with the eyeball in the properties or if it is hidden with a hide action.

     

    The "visible" will always return true or 1, unless the element it is turned off with the action "hide"

    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    June 9, 2022

    You can do it with this script:

     

    cp.model.data.SmartShape_2c.effectiveVi;

     

    The bold text is the name of the element you want to check. You must append the "c" to the name of the element.

    Known Participant
    June 10, 2022

    Thanks for the answer.

    I'll try this and stagprimes solution ... just to learn both 🙂

    I have both the canvas object and the object stored in a nodelist.

    Stagprime2687219
    Legend
    June 9, 2022

    This question came up a short while ago.

    You can see my response to that post using the link below.

    https://community.adobe.com/t5/captivate-discussions/how-do-you-know-if-an-object-is-hidden-with-javascript/m-p/12960595

     

    Known Participant
    June 10, 2022

    Thank you!

    I did look before I posted, but didn't find that one.

    Paul Wilson CTDP
    Community Expert
    Community Expert
    June 9, 2022

    The easiest way is also to have a variable assigned a value of 1 or 0 depending on the object's condition. That way you can check the value of the variable as part of an advanced action. For example, I frequently assign variables to button clicks in my Captivate projects so I can determine if the learner has pressed all the buttons in an interaction. Here is an example of what I'm talking about. https://www.youtube.com/watch?v=BItqVz3OfGE 

    Paul Wilson, CTDP
    Known Participant
    June 10, 2022

    Thanks for the reply, but this won't work in my case.

    This is a tamplate-page that will be duplicated and the content (images, text, sound) swapped out by others than myself. I need to know at the start of the page, at runtime, how many buttons are visible ... and I don't know the exact ID. I just have them stored in a nodelist.
    Stagprimes solution will work though 🙂