Search code examples
jquerydoubleslash

jQuery: how to write the double slash '//' so that it does not throw error?


I have this code:

(options.parent) ? top = options.parent.height / 2; : top = parent.height() / 2;

Because of the double slash that i use there it get's an error i know why i get the error i just don't know how to write it to work.
Thanks again.


Solution

  • It has nothing to do with the "double slashes", remove the semicolon

    (options.parent) ? top = options.parent.height / 2 
                     :top = parent.height() / 2;
    

    Semicolon was meant to define end of statement(optional), the ternary operator is treated as a single statement.

    (options.parent) ? top = options.parent.height / 2; : top = parent.height() / 2;
    //                                                ^------ Wrong!