www.webdeveloper.com
Results 1 to 5 of 5

Thread: What does ? mean?

  1. #1
    Join Date
    Mar 2004
    Posts
    22

    What does ? mean?

    I am fairly new to JS and I am confused what the ? operator does.

    Example:

    menu.style.display = (display == "block") ? "none" : "block";

    I have no idea what this line does, can someone please explain?

    Thanks!

  2. #2
    Join Date
    Jul 2003
    Location
    Wales
    Posts
    1,382
    Well, what you have posted is a shortuct for an IF ELSE statement so, the ? is to go to the actuall assigning of values within the statement, it goes like this:

    (Expression) ? Do Something If True : Do Something If False.


    Hope that helps.
    Cheers,

    Ryan Jones.

  3. #3
    Join Date
    Mar 2004
    Posts
    22
    Thanks, makes sense!

    I am using Dave Lindquist's script (www.gazingus.org) for an expandable menu. Here is a piece of code that changes the menu from closed to open and vice-versa.

    actuator.onclick = function() {
    var display = menu.style.display;
    this.parentNode.style.backgroundImage =
    (display == "block") ? "url()" : "url()";
    menu.style.display = (display == "block") ? "none" : "block";

    return false;
    }

    This is nested inside another function which initializes the menu names. I am trying to modify the script so that the menus will default to expanded.

    I am reading the code and have fiddled with it, but no luck.

    I get that the actuator (which is a defined variable earlier that points to the menu heading) when clicked runs this function. I do not understand how it can tell to oscilate between open and closed.

    Thoughts?

    Thanks!

  4. #4
    Join Date
    Mar 2004
    Posts
    22
    Ok, I get it now.

    I did a search on menu.style.display and figure out that if I initialize it to "block" by adding

    menu.style.display = "block";

    This causes the menus to default to open.

    Thanks for the previous help!

    Ian

  5. #5
    Join Date
    Jul 2003
    Location
    Wales
    Posts
    1,382
    No Problem and in reply to your second question try adding something like this after the function(){ line:

    menu.style.display = "block";
    Cheers,

    Ryan Jones.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles