jquery if/else block problem
<p>I'm having a problem with an if/else block.  The problem is that the else block is always executing. When the click happens, if two select elements have both have a class of "current-drop" then only the if block should execute.  </p>

<p>However, since those two classes are being removed at the end of the if block (the classes are added again later using the <code>change()</code> method) then I suppose that is causing the else block to execute. Is it because the click event isn't finished firing when the classes are removed, causing the conditions to change?  </p>

<p>How can I work around this? </p>

<pre><code>$('.add-button').click(function() {

var class1=$("#select-pub").attr('class');
var class2=$("#select-segment").attr('class');

if ((class1=='current-drop') &amp;&amp; (class2=='current-drop')) {

    $('&lt;li /&gt;', {text: $('#select-pub option:selected').text()})
    .appendTo('div #publisher-results ul');
    $('&lt;li /&gt;', {text: $('#select-segment option:selected').text()})
    .appendTo('div #segment-results ul');
    $('#select-pub').removeClass('current-drop');
    $('#select-segment').removeClass('current-drop');
    $('#error-message').css('visibility','hidden');
}

else
{
    $('#error-message').css('visibility','visible');
}

});
</code></pre>

<p>edit: Here is the page - yes I know it is a bit of a soupy mess right now...</p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
    &lt;title&gt;Group Commerce | Dashboard&lt;/title&gt;
    &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8" /&gt;

    &lt;link type="text/css" rel="stylesheet" href="fancybox/jquery.fancybox-1.3.1.css"/&gt;
   &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="js/add-items-over.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="fancybox/jquery.fancybox-1.3.1.pack.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript"&gt;
    $(document).ready(function() {


    $("a#click-up").fancybox({
        'padding':0,
        'margin':0,
        'scrolling':'no',
        'showCloseButon':'true',
        'overlayColor':'#dfdfdf'
        });



});
&lt;/script&gt;



 &lt;style type="text/css"&gt;
        /* Custom Theme */


        h1 {font-family:verdana;font-size:18px; color:#122652;padding:30px 0 0 20px;}

        table {width:577px;margin-left:20px;
        border:1px solid #d5d5d5;font-family:arial; font-size:11px;}

        table td {
            border-right:1px solid #d5d5d5;
            padding:5px 0 5px 5px;
            }

        tr.table-bg td {
            border-bottom:1px solid #d5d5d5;
            font-weight:bold;
            background:url(images/table-top-bg.jpg) repeat-x;
            }

        #modal-left {
            width:272px;
            margin-top:-11px;
            float:left;
            }

        #modal-right {
            width:335px;
            float:right;
            margin-top:-11px;
            }

            #error-message {
            margin-bottom:15px;

        margin-left:20px;
            margin-top:5px;
            }

            .error-default {
                color:red;
                }

            .error-message-no {
                visibility:hidden !important;
                }

        .error-message-yes {
                visibility:visible;
                }

        #modal-left p {
            margin-left:20px;
            }

        #modal-left a, #modal-right a {
            background:url(images/add-select.gif) no-repeat;
            margin-top:-1px;
            }

        #modal-left a {
            position:relative;
            right:2px;
            }



            .select-div {
                width:272px;
                float:left;
                }

            .link-div {
                width:46px;
                height:22px;
                float:right;
                margin-top:30px;
                }

            #modal-left select {
            margin-left:20px;
            width:252px;
            }

            #publisher-results {
                background-color:#f9f9f9;
                width:252px;
                height:100px;
                margin-left:20px;
                margin-top:5px;
                }

            #segment-results {
                background-color:#f9f9f9;
                width:252px;
                height:100px;
                margin-top:3px;
                }

            .select-div2 {
                width:220px;
                float:left;
                }

            .select-div2 select {
                width:252px;
                }

            .link-div2 {
                width:46px;
                height:22px;
                float:right;
                position:relative;
                right:22px;
                }

            #modal-right a {
            background:url(images/add-select.gif) no-repeat;
            position:relative;
            right:2px;
            }

            #publisher-results {
                overflow:hidden;
                }

            #publisher-results ul {
                margin-top:5px !important;
                }

            #publisher-results li {
                list-style:none;
                position:relative;
                right:30px;
                margin-bottom:3px;
                }

            #segment-results {
                overflow:hidden;
                }

            #segment-results ul {
                margin-top:5px !important;
                }

            #segment-results li {
                list-style:none;
                position:relative;
                right:30px;
                margin-bottom:3px;
                }

            #footer {
                text-align:right;
                margin-top:150px;
                width:100%;
                padding-right:30px;
                }

            #footer-submit  {
                display:block;
                float:right;
                width:116px;
                height:22px;
                background:url(images/submit-to-copy.gif) no-repeat;
                position:relative;
                right:12px;
                margin-left:10px;
                }

            #footer-cancel {
                display:block;
                float:right;
                width:68px;
                height:22px;
                background:url(images/cancel.gif) no-repeat;
                position:relative;
                right:12px;
                }
            #box-content {
                border:1px solid white;
                }

    &lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;div id="modal-wrap"&gt;
&lt;a id="click-up" href="#box-content"&gt;Click here for popup&lt;/a&gt;

&lt;div style="display:none;"&gt;
&lt;div id="box-content" style="width:620px;height:335px;background:url(images/modal-bg.gif) left top no-repeat;"&gt;
&lt;h1&gt;Send the following deal to copy stage...&lt;/h1&gt;

&lt;table border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr class="table-bg"&gt;
&lt;td&gt;Vendor&lt;/td&gt;
&lt;td&gt;Vendor ID&lt;/td&gt;
&lt;td style="width:100px;"&gt;Offer&lt;/td&gt;
&lt;td&gt;Status&lt;/td&gt;
&lt;td&gt;Availability Start&lt;/td&gt;
&lt;td style="border-right:none;"&gt;Availability End&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Apple&lt;/td&gt;
&lt;td&gt;10010000111&lt;/td&gt;
&lt;td&gt;$2.99 app&lt;/td&gt;
&lt;td&gt;Ready for Market&lt;/td&gt;
&lt;td&gt;9/20/2010&lt;/td&gt;
&lt;td style="border-right:none;"&gt;9/20/2010&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p id="error-message"&gt;&lt;em&gt;Both the publisher and the segment fields are required!&lt;/em&gt;&lt;/p&gt;
&lt;div id="modal-left"&gt;



&lt;script type="text/javascript"&gt;

$(document).ready(function() {

$('#error-message').addClass('error-default');
$('#select-pub').change(function() {
$(this).addClass('current-drop');
}); 

$('#select-segment').change(function() {
$(this).addClass('current-drop');
}); 


$('.add-button').click(function() {

var class1=$("#select-pub").attr('class');
var class2=$("#select-segment").attr('class');
if ($('#select-pub').hasClass('current-drop') &amp;&amp; $('#select-segment').hasClass('current-drop')) {

    $('&lt;li /&gt;', {text: $('#select-pub option:selected').text()})
    .appendTo('div #publisher-results ul');
    $('&lt;li /&gt;', {text: $('#select-segment option:selected').text()})
    .appendTo('div #segment-results ul');
    $('#select-pub').removeClass('current-drop');
    $('#select-segment').removeClass('current-drop');
    $('#error-message').css('visibility','hidden');
    }

    /*else
    {
    $('#error-message').css('visibility','visible');
    }*/

});
});

&lt;/script&gt;



&lt;div class="select-div"&gt;

&lt;select id="select-pub"&gt;
&lt;option val="1" selected&gt;Publisher 1&lt;/option&gt;
&lt;option val="2"&gt;Publisher 2&lt;/option&gt;
&lt;option val="3"&gt;Publisher 3&lt;/option&gt;
&lt;option val="4"&gt;Publisher 4&lt;/option&gt;
&lt;/select&gt; 

&lt;/div&gt;

&lt;!--&lt;div class="link-div"&gt;
&lt;a class="add-button" href="#" style="width:46px;height:22px;display:block;"&gt;&lt;/a&gt;
&lt;/div&gt;--&gt;

&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;div id="publisher-results"&gt;
&lt;ul&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;/div&gt;


&lt;script type="text/javascript"&gt;

$(document).ready(function() {

$('.add-button-2').click(function() {
$('&lt;li /&gt;', {text: $('#select-segment option:selected').text()})
.appendTo('#segment-results ul');
$('#segment-results ul li:odd').css('display','none');
});

});

&lt;/script&gt;
&lt;div id="modal-right"&gt;

&lt;div class="select-div2"&gt;
&lt;select id="select-segment"&gt;

&lt;option selected&gt;Segment 1&lt;/option&gt;
&lt;option&gt;Segment 2&lt;/option&gt;
&lt;option&gt;Segment 3&lt;/option&gt;
&lt;option&gt;Segment 4&lt;/option&gt;
&lt;/select&gt;

&lt;/div&gt;

&lt;div class="link-div2"&gt;
&lt;a href="#" class="add-button" style="width:46px;height:22px;display:block;"&gt;&lt;/a&gt;
&lt;/div&gt;

&lt;div style="clear:both;"&gt;&lt;/div&gt;
&lt;div id="segment-results"&gt;
&lt;ul style="margin:0;"&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="footer"&gt;

&lt;a href="#" id="footer-submit"&gt;&lt;/a&gt;
&lt;a href="javascript:;" onclick="$.fancybox.close();" id="footer-cancel"&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
