I have a function to display or hide some elements. What I want to do is to manage the display of those elements regarding a value.How should I replace the term toggle? Toggling for me means 'show the element if it's hidden, or hide it if it shown.' (yes, I mean toggling visibility)function togglePassengers() {    var nbPassengers = $(#nbPassengersForTravel).val(),        $passengers = $('#d_passenger').find('fieldset');    $passengers.each( togglePassenger );    function togglePassenger(i){        $passenger = $(this);        if( ++i <= nbPassengers )            showPassenger($passenger);        else            hidePassenger($passenger);    }    function showPassenger($passenger){        $passenger            .removeClass(hidden)            .find(select.age option[value='-1']).remove();    }    function hidePassenger($passenger){        $passenger.addClass(hidden);        var $passengerAge = $passenger.find(select.age);        if ( ! $passengerAge.find(option[value='-1']:first-child).length )            $passengerAge.prepend(<option value='-1'>---------</option>).val('-1');    }}
How should I name a function which shows or hides an element?
javascript;jquery
NamingI think togglePassenger is not the only naming problem in your code. A function parameter should not be a single letter except in a very limited number of cases. But I don't think that this is not one of them; a reader does not automatically understand what i actually does.I would also rename nbPassengers, because it is unclear what nb means.What I think your function does is show the first n passengers, and hide the rest. If that is the case, I would not use toggle, because as you said, there really is no toggling going on. You could go with something like updateVisibility to avoid this confusion, although it's a bit unconcrete. Whatever name you do choose, I would add a comment to the function explaining what it does.MiscI would use curly brackets even for one line statements to avoid future bugsyour spacing is sometimes inconsistent (eg spacing around variable in function calls)