There are no tracking or monitoring cookies on this site. There are only cookies used for documentation examples related to cookies.
Close

Processing...
This may take a few seconds.

if-func

Syntax

if-func: (name of function);

This conditional function will return true if the external function referenced returns true. The external function will be in your external JavaScript. It must be publicly available as a function, so it needs to be in the window scope.

name of function = The external function to call.

Your function must either return true or false. You can write whatever you like in the function, get it performing DOM manipulation, whatever, but it must return true or false to be an acceptable conditional. Not returning true or false may produce unexpected results.

There is an object that always gets sent to your external function. This object contains information about the event, values, etc.

In this example, this conditional will pass as true if the external function simpleAdd() returns true.

@conditional basicArith {
    if-func: simpleAdd;
}

Here is the "simpleAdd" Javascript function it calls - note the Active CSS object passed which isn't actually being used here (in this example it is "o", but you can name it anything valid):

function simpleAdd(o) {
    let a = 1;
    let b = 1;
    let c = a + b;
    return (c == 2) ? true : false;
}

For more information on the "o" object, or in other words the object that gets sent to your function, see the func action command in the "Actions" section of the docs.

JavaScript expression use

As with all the conditionals, a JavaScript expression can be used when appropriate. In this particular conditional command, a response of true or false from a JavaScript expression is a valid response rather than returning the function name as a string, as you can call a function from within a JavaScript expression. But if you return a string from a JavaScript expression which contains the name of a function, this will be ran in the command.