if(.is-open close-now){ jQuery(".extra_div").click(function($){             alert('"Sorry, this takeaway only accepts orders during its opening hours"');         }); }   I think something like the above is what I need but I don't know how the if statement part should work out.  I'm looking to check if a certain div is present and then if it is, run the following jQuery on click code.  Update 1  if ($(.is-open close-now).length){ jQuery(".extra_div").click(function($){             alert('"Sorry, this takeaway only accepts orders during its opening hours"');         }); }   The two divs are   is-open open-now - open .is-open close-now - closed
9151
How can I check the existence of an element in jQuery?  The current code that I have is this:  if ($(selector).length &gt; 0) {     // Do something }   Is there a more elegant way to approach this? Perhaps a plugin or a function?
17578
In Mootools, I'd just run if ($('target')) { ... }.  Does if ($('#target')) { ... } in jQuery work the same way?
34496
I have the following html code:   &lt;h3 id="headerid"&gt;&lt;span onclick="expandCollapse('headerid')"&gt;&amp;uArr;&lt;/span&gt;Header title&lt;/h3&gt;   I would like to toggle between up arrow and down arrow each time the user clicks the span tag.   function expandCollapse(id) {        var arrow = $("#"+id+" span").html(); // I have tried with .text() too     if(arrow == "&amp;dArr;") {              $("#"+id+" span").html("&amp;uArr;");                    } else {                 $("#"+id+" span").html("&amp;dArr;");                    } }   My function is going always the else path. If I make a javacript:alert of arrow variable I am getting the html entity represented as an arrow. How can I tell jQuery to interpret the  arrow variable as a string and not as html.
92519
I have HTML like the following on my website:  &lt;div class="groups"&gt;   &lt;div class="group"&gt;     Group 1 priority:     &lt;select&gt;       &lt;option value="1.0"&gt;1&lt;/option&gt;       &lt;option value="2.0" selected="selected"&gt;2&lt;/option&gt;       &lt;option value="3.0"&gt;3&lt;/option&gt;     &lt;/select&gt;   &lt;/div&gt;   &lt;div class="group"&gt;     Group 2 priority:     &lt;select&gt;       &lt;option value="1.0"&gt;1&lt;/option&gt;       &lt;option value="2.0"&gt;2&lt;/option&gt;       &lt;option value="3.0" selected="selected"&gt;3&lt;/option&gt;     &lt;/select&gt;   &lt;/div&gt;   &lt;div class="group"&gt;     Group 3 priority:     &lt;select&gt;       &lt;option value="1.0" selected="selected"&gt;1&lt;/option&gt;       &lt;option value="2.0"&gt;2&lt;/option&gt;       &lt;option value="3.0"&gt;3&lt;/option&gt;     &lt;/select&gt;   &lt;/div&gt; &lt;/div&gt;   I am looking for a way to sort the order these groups appear in the browser using jQuery, based on the what is selected in the dropdown. It should resort when the user selects a new value in any of the dropdowns, or on page load.  What would be the easiest approach to this problem?  I have jQuery UI available, if the sortable thing can be used in any way. I couldn't not find a way to use that.  Update: There is other data in the &lt;div class="group"&gt; that should follow the dropdowns wherever they are moved. The number of groups varies from 0 to 20.
116653
I have this:  If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then     stTransactionPaymentID = editTransactionRow.pay_id 'Check for null value End If   Now, when editTransactionRow.pay_id is Null Visual Basic throws an exception. Is there something wrong with this code?
36944
I have the following code that's not working as expected:  If Sheets("a") &lt;&gt; "" Then MsgBox ("sheet a exists")   How can I tell if sheet a exists in the workbook?
23917
Which is the right thing to do?  if (myObj['key'] == undefined)   or  if (myObj['key'] == null)   or  if (myObj['key'])
123225
I'm looking for something like alert(), but that doesn't "pause" the script.  I want to display an alert and allow the next command, a form submit(), to continue. So the page will be changing after the alert is displayed, but it won't wait till the user has clicked OK.  Is there something like this or is it just one of those impossible things?
26323
I have an ArcGIS JavaScript API Web App that uses multiple combo boxes.  I would like to create an if-else conditional statement between two fields in my feature layer.  If one field is chosen in combo box one is 1  then combo box three should automatically populate to 3.    Below is my validate function for my request type.    function changeonevent() {   (dijit.byId("cbRequestType").on('change'), changeonevent (MFValue) {     if (MFValue == 'Electronic Waste') {    dijit.byID("cbMFSubType"). set ('value', 'Copy Machine');     } else if MFValue == '...'{    dijit.by.ID('cbMFSubType').set('value', 'Printer');     }
100032
How exactly do you make an auto-refreshing div with JavaScript (specifically, jQuery)?  I know about the setTimeout method, but is it really a good practice ? Is there a better method?  function update() {     $.get("response.php", function(data) {         $("#some_div").html(data);     });     window.setTimeout("update();", 10000); }
76419
I'm using jQuery to hide and show elements when a radio button group is altered/clicked. It works fine in browsers like Firefox, but in IE 6 and 7, the action only occurs when the user then clicks somewhere else on the page.  To elaborate, when you load the page, everything looks fine. In Firefox, if you click a radio button, one table row is hidden and the other one is shown immediately. However, in IE 6 and 7, you click the radio button and nothing will happen until you click somewhere on the page. Only then does IE redraw the page, hiding and showing the relevant elements.  Here's the jQuery I'm using:  $(document).ready(function () {   $(".hiddenOnLoad").hide();    $("#viewByOrg").change(function () {     $(".visibleOnLoad").show();     $(".hiddenOnLoad").hide();   });    $("#viewByProduct").change(function () {     $(".visibleOnLoad").hide();     $(".hiddenOnLoad").show();   }); });   Here's the part of the XHTML that it affects. The whole page validates as XHTML 1.0 Strict.  &lt;tr&gt;   &lt;td&gt;View by:&lt;/td&gt;   &lt;td&gt;     &lt;p&gt;       &lt;input type="radio" name="viewBy" id="viewByOrg" value="organisation"       checked="checked" /&gt;Organisation&lt;/p&gt;     &lt;p&gt;       &lt;input type="radio" name="viewBy" id="viewByProduct" value="product" /&gt;Product&lt;/p&gt;   &lt;/td&gt; &lt;/tr&gt; &lt;tr class="visibleOnLoad"&gt;   &lt;td&gt;Organisation:&lt;/td&gt;   &lt;td&gt;     &lt;select name="organisation" id="organisation" multiple="multiple" size="10"&gt;       &lt;option value="1"&gt;Option 1&lt;/option&gt;       &lt;option value="2"&gt;Option 2&lt;/option&gt;     &lt;/select&gt;   &lt;/td&gt; &lt;/tr&gt; &lt;tr class="hiddenOnLoad"&gt;   &lt;td&gt;Product:&lt;/td&gt;   &lt;td&gt;     &lt;select name="product" id="product" multiple="multiple" size="10"&gt;       &lt;option value="1"&gt;Option 1&lt;/option&gt;       &lt;option value="2"&gt;Option 2&lt;/option&gt;     &lt;/select&gt;   &lt;/td&gt; &lt;/tr&gt;   If anyone has any ideas why this is happening and how to fix it, they would be very much appreciated!
84374
I’ve had a good look and can’t seem to find out how to select all elements matching certain classes in one jQuery selector statement such as this:  $('.myClass', '.myOtherClass').removeClass('theclass');   Any ideas on how to achieve this? The only other option is to do  $('.myClass').removeClass('theclass'); $('.myOtherClass').removeClass('theclass');   But I’m doing this with quite a few classes, so it requires much code.
94684
Could someone explain me what does this statement mean and what option should I click when it pops up?
85862
This page does it the way I want it to:   But I want to find a better way using jQuery, can anyone point me to a good script that uses jQuery to accomplish this?
34565
I have a javascript routine that is performing actions on a group of checkboxes, but the final action I want to set the clicked checkbox to checked or unchecked based on if the user was checking the box or unchecking.  Unfortunately, every time I check for whether it is being checked or unchecked, it returns "on" indicating the user is always checking the box!  Any help would be appreciated, I've also included the javascript.  // Uncheck all the checkboxs with the same Tax Credit for (i=0; i&lt;arrChecks.length; i++) {     var attribute = arrChecks[i].getAttribute("xid")     if (attribute == elementName)     {         // if the current state is checked, unchecked and vice-versa         if (arrChecks[i].value == "on")   // &lt;-- This is always returning true, even if the box is being unchecked         {             arrChecks[i].checked = 1;         } else {             arrChecks[i].checked = 0;         }      } else {         arrChecks[i].checked = 0;     } }
28108
If i do jQuery(expr).change( function), then I can get an event function to fire when the user makes a change to the value.  Is it possible to get this to fire if it's changed programatically, ie if I call jQuery(expr).val("moo").  or if some Plain old JavaScript changes it's value?  Thanks for any help.
22621
I have done the following code in JavaScript to put focus on the particular element (branch1 is a  element),  document.location.href="#branch1";   But as I am also using jQuery in my web app, so I want to do the above code in jQuery. I have tried but don't know why its not working,  $("#branch1").focus();   The above jquery (focus()) code is not working for div, whereas If i am trying the same code with textbox, then its working,  Please tell me, how can I put focus on a div elemnt using jQuery?  Thanks!