Error writing IF and Else in jquery [duplicate]

1

I'm starting to venture into the development world now and hit a question when using IF and Else.

The code below is OK

    <select id="course_list" >
      <?php $my_query = new WP_Query('tribe_events_cat=petroleo-e-gas'); ?>
         <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <option value="course_<?php the_ID(); ?>" >
                <?php the_title(); ?>
            </option>
        <?php endwhile; ?>
    </select>

<script type="text/javascript">
$("#course_list").on('change', function(){
        $('.course_item').hide();
        $('#' + this.value).show();

    });
</script>

But when I try to refine the code and show all courses again, everything has stopped working.

<select id="course_list" >
        <?php $my_query = new WP_Query('tribe_events_cat=petroleo-e-gas'); ?>
        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <option value="all-posts" >
            Mostrar Todos
        </option>
        <option value="course_<?php the_ID(); ?>" >
            <?php the_title(); ?>
        </option>
        <?php endwhile; ?>
    </select>
    <script type="text/javascript">
    $("#course_list").on('change', function(){

        if {
            $('.course_item').hide();
            $('#' + this.value).show();
           }

        else

            $('.course_item=').show();


        });
    </script>
    
asked by anonymous 27.08.2015 / 09:54

1 answer

1

Hello

Your code has a syntax error in the "if else" block. To correct you need to put a condition to be tested inside the if. For example:

if(ALGUMA_VARIAVEL == CONDICAO) {
    $('.course_item').hide();
    $('#' + this.value).show();
} else
    $('.course_item=').show();

If the condition is satisfied at some point, its 'if' block will be executed, otherwise 'else' will always be executed.

    
27.08.2015 / 16:00