I'm making an A/B test (Injecting code onto a page) to increase the images of products in your shopping cart.  When you select a different shipping method - the whole table appears to be refreshed.   and my code will only execute the first time.  So when i select a different shipping method the second time. my code is lost.  Except the  tags stay.  You'll need to have a random product in your cart to see it first.    &lt;script&gt; $( document ).ready(function() {  $('img.item-img').each(function() {     var str      = $(this).attr('src'),         arr      = str.split("?");   query  = "?hei=200&amp;wid=200&amp;op_sharpen=1"     $(this).attr('src', arr[0] + query);  });         $( document ).ready(function() {     $('tr').each(function() {   var desc = $('td.description', this).html()    $('td.image', this).append(desc);   $('td.description', this).remove(); });   $("table#shopping-cart-items tr td.image").after($('&lt;td id="clearSpace"&gt;&lt;/td&gt;'));  }); });        &lt;/script&gt;     &lt;script&gt;         $( document ).ready(function() {     $('div.shippingOpt').click(function() {          window.setTimeout(function(){          $('img.item-img').each(function() {     var str      = $(this).attr('src'),         arr      = str.split("?");   query  = "?hei=200&amp;wid=200&amp;op_sharpen=1"     $(this).attr('src', arr[0] + query);  });       $('tr').each(function() {   var desc = $('td.description', this).html()    $('td.image', this).append(desc);   $('td.description', this).remove(); });                         $("table#shopping-cart-items tr td.image").after($('&lt;td id="clearSpace"&gt;&lt;/td&gt;'));                 }, 1000);                                }); });      &lt;/script&gt; &lt;style&gt;     .checkoutBasket table.cart-container td.image img { width:200px; height:auto;}     #clearSpace  {padding: 0 0 0 15px;} &lt;/style&gt;
112
I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off.  This happens on page ready and works just fine.  The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound.  I have found this plugin (), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this, either with jQuery directly or by another option.
51498
&lt;table&gt;          &lt;apex:repeat value="{!dataList}" var="List" id="dataTable"&gt;             &lt;tr&gt;                  &lt;th&gt;   Name &lt;/th&gt;                &lt;th&gt;   Status&lt;/th&gt;             &lt;/tr&gt;              &lt;tr&gt;                  &lt;td&gt;   &lt;apex:inputField value="{!List.Name}"/&gt; &lt;/td&gt;                &lt;td&gt;    &lt;apex:inputField value="{!List.Status__c}"/&gt;&lt;/td&gt;             &lt;/tr&gt;           &lt;/apex:repeat&gt;   &lt;/table&gt;     I want all rows to display horizontally not vertically i.e. in the same line one after another instead of in next line. How can this be done? The headings and values, both should be repeated horizontally.
54988
I would like to see the review page refresh automatically if I have done some reviews and get the message that there are currently no more reviews to perform.  Refreshing the whole page is, in my opinion, a little too much overhead. The review itself seems to work with AJAX. So, a small refresh button to trigger would be nice too, if the real-time updates are too complex.
19010
My  script has now gained quite a following (and it - allegedly - just got bust by upgrading to jQuery 1.7.1). This is a personal request to the team to consider adopting it.   Not that I don't wish to keep on maintaining it, but the next step (allowing users to define one global set of comments to be used across all their sites*) is pretty awkward for me to implement "from the outside", but would be comparatively trivial for the team (I believe).  Goes off to fix script...  * Note: I have a beta half-version of this; it requires   userscripts, and allows you to push/pull between "local" (site-specific) and "global" storage. And even if I get the global sharing 'properly' working, it would still only be for a given machine.
32885
I have some html like this:  &lt;div id="1"&gt;     &lt;p&gt;         Volume = &lt;input type="text" /&gt;         &lt;button rel="3.93e-6" class="1" type="button"&gt;Check answer&lt;/button&gt;     &lt;/p&gt;     &lt;div&gt;&lt;/div&gt; &lt;/div&gt;   and some JS like this:  $("button").click(function () {     var buttonNo = $(this).attr('class');     var correct = Number($(this).attr('rel'));      validate (Number($("#"+buttonNo+" input").val()),correct);     $("#"+buttonNo+" div").html(feedback); });   What I'd really like is if I didn't have to have the class="1" on the button (I know numeric classes aren't valid, but this is a WIP!), so I could determine buttonNo based on the id of the parent div. In real life there are multiple sections looking like this.   How do I find the id of the div parenting the button. What would be a more semantic way to store the answer in the button code. I want to make this as foolproof as possible for a non programmer to copy and paste without breaking things!
9360
When the OP posted , the contents looked like "AAAA AAAA AAAAAAAAA". Obviously, no-one was going to understand this, so we downvoted and voted to close. After closure, I immediately voted to delete the question. A few seconds later, the OP updated the question. I voted to re-open, and a few minutes later, the question was re-opened.  I've just reviewed the Q&amp;A, and it's garbage:   The question is unclear (the fiddle doesn't match the question's code). The only answer was was invalidated after the question was updated again (it pointed to a typo). The invalid answer was accepted with the  "My problem was somewhere else but I did learn that JSFiddle needs the tag table. thanks" (note: has nothing to do with the question).   For these reasons, I decided to cast a close vote, which summoned the following screen:   As you can see, there are no pending close votes, but the screen still shows that I have already cast a close vote. This looks like a bug (possibly caused by my previous delete vote?).
30444
So...here is part of my code for a plugin.  I'm a newb of sorts so be kind.  I've read up on global variables but I can't seem to get it to work and I've read you shouldn't use them anyway.  So what would be the best way to write the code below without having to re-declare the variables for each function?  Here is the  if necessary.  // Display the product badge on the shop page  add_action( 'woocommerce_after_shop_loop_item_title', 'wc_simple_product_badge_display_shop', 30 ); function wc_simple_product_badge_display_shop() {     $title = get_post_meta( get_the_ID(), '_wc_simple_product_badge_title', true ); // badge title     $class = get_post_meta( get_the_ID(), '_wc_simple_product_badge_class', true ); // badge class     $duration = get_post_meta( get_the_ID(), '_wc_simple_product_badge_duration', true ); // badge duration     $postdate = get_the_time( 'Y-m-d' ); // post date     $postdatestamp = strtotime( $postdate ); // post date in unix timestamp     $difference = round ((time() - $postdatestamp) / (24*60*60));  // difference in days between now and product's post date      if ( !empty( $title ) &amp;&amp; empty( $duration ) || !empty( $title ) &amp;&amp; $difference &lt;= $duration ){ // Check to see if there is a title and the product is still within the duration timeframe if specified         $class = !empty( $class ) ? $class : '';         echo '&lt;span class="wc_simple_product_badge ' . $class . '"&gt;' . $title . '&lt;/span&gt;';     } }  // Display the product badge on the single page  add_filter( 'woocommerce_single_product_image_html', 'wc_simple_product_badge_display_single' );     function wc_simple_product_badge_display_single( $img_html ) {     $title = get_post_meta( get_the_ID(), '_wc_simple_product_badge_title', true ); // badge title     $class = get_post_meta( get_the_ID(), '_wc_simple_product_badge_class', true ); // badge class     $duration = get_post_meta( get_the_ID(), '_wc_simple_product_badge_duration', true ); // badge duration     $single_opt = get_post_meta( get_the_ID(), '_wc_simple_product_badge_single_page_option', true ); // badge on single page     $postdate = get_the_time( 'Y-m-d' ); // post date     $postdatestamp = strtotime( $postdate ); // post date in unix timestamp     $difference = round ((time() - $postdatestamp) / (24*60*60));  // difference in days between now and product's post date      if ( !empty( $title ) &amp;&amp; empty( $duration ) &amp;&amp; $single_opt === 'yes' || !empty( $title ) &amp;&amp; $difference &lt;= $duration &amp;&amp; $single_opt === 'yes' ){ // Check to see if there is a title and the product is still within the duration timeframe ()if specified) and the checkbox is checked to show on single page view         $class = !empty( $class ) ? $class : '';         echo '&lt;span class="wc_simple_product_badge ' . $class . '"&gt;' . $title . '&lt;/span&gt;';         return $img_html; }      elseif ( $single_opt === 'no' ) { // Check to see if the checkbox is unchecked to show on single page view         return $img_html;     }  }
104708
I'm working on a web page where I'm making an AJAX call that returns a chunk of HTML like:   &lt;div&gt;   &lt;!-- some html --&gt;   &lt;script type="text/javascript"&gt;     /** some javascript */   &lt;/script&gt; &lt;/div&gt;   I'm inserting the whole thing into the DOM, but the JavaScript isn't being run.  Is there a way to run it?    Some details: I can't control what's in the script block (so I can't change it to a function that could be called), I just need the whole block to be executed.  I can't call eval on the response because the JavaScript is within a larger block of HTML.  I could do some kind of regex to separate out the JavaScript and then call eval on it, but that's pretty yucky.  Anyone know a better way?
10734
I'm using jQuery to wire up some mouseover effects on elements that are inside an UpdatePanel. The events are bound in $(document).ready . For example:  $(function() {         $('div._Foo').bind("mouseover", function(e) {         // Do something exciting     });     });   Of course, this works fine the first time the page is loaded, but when the UpdatePanel does a partial page update, it's not run and the mouseover effects don't work any more inside the UpdatePanel.   What's the recommended approach for wiring stuff up in jQuery not only on the first page load, but every time an UpdatePanel fires a partial page update? Should I be using the ASP.NET ajax lifecycle instead of $(document).ready?
92924
I have added an announcement web App, to SP2013 my team site, and for the App part Ajax option I enabled the following:-   Enable Asynchronous Update Show Manual Refresh Button Enable Asynchronous Automatic Refresh Automatic Refreshing Interval (seconds) = 60.   But on Safari after 60 seconds or when the user manually clicks on the “Refresh” button,  the current web page will do a full reload and not an asynchronous reload. While on IE, FireFox and Chrome they will do asynchronous reload. can anyone advice ?
106949
I'd love some other opinions on what's more efficient in this code. Basically in the following code, there's a setInterval loop and I need 4 requirements to be true before the code runs in the loop. So in v.1 I wrote an if statement checking all 4. Worked fine.  Then I switched to just using try/catch, with the code I want to execute sitting in try{}. The logic was that during each loop, an exception would be generated but suppressed for each invalid condition. On the final loop where all conditions are true, the code executes and clears the interval.  Either works. I like the try/catch method because there's less conditional code that I need to write and worry about breaking. But I'm worried that try/catch is really inefficient, especially in a setInterval() loop hitting at 100ms. What are some opinions of other bright minds here on SO?  Try/Catch  var intvar = setInterval(function(){ try{         clearInterval(intvar);      jQuery('#'+nav[pageid].t1+'&gt;a').replaceWith(jQuery('&lt;span&gt;'+jQuery('#'+nav[pageid].t1+'&gt;a').text()+'&lt;/span&gt;'));      //set display classes for nav     jQuery('#'+nav[pageid].t1).addClass('selected').find('#'+nav[pageid].t2).addClass('subselect'); //topnav     jQuery('#'+nav[pageid].t3).addClass('selected').find('#'+nav[pageid].t4).addClass('subselect'); //leftnav }catch(err){} },100);   IF Block  var intvar = setInterval(function(){  if(typeof jQuery == 'function' &amp;&amp; typeof nav == 'object' &amp;&amp; typeof pageid != 'undefined' &amp;&amp; typeof document.getElementById('leftnav') == 'object'){     clearInterval(intvar);     jQuery('#'+nav[pageid].t1+'&gt;a').replaceWith(jQuery('&lt;span&gt;'+jQuery('#'+nav[pageid].t1+'&gt;a').text()+'&lt;/span&gt;'));      //set display classes for nav     jQuery('#'+nav[pageid].t1).addClass('selected').find('#'+nav[pageid].t2).addClass('subselect'); //topnav     jQuery('#'+nav[pageid].t3).addClass('selected').find('#'+nav[pageid].t4).addClass('subselect'); //leftnav }  },100);
60845
I have used this jquery script on many of my sites with the same theme, settings, etc.  It's in a wordpress Genesis Child theme.  On my current local build, however, when I click on an a href that has the class "scroll", I am getting a console error that reads:    Line 19 of my app.js is this code that I have never had an issue with before:  $(".scroll").click(function () {         if (location.pathname.replace(/^\//, "") === this.pathname             .replace(/^\//, '') &amp;&amp; location.hostname === this.hostname         ) {             var target = $(this.hash);             target = target.length ? target : $("[name=" + this                 .hash.slice(1) + "]");             if (target.length) {                 $("html, body").animate({                     scrollTop: target.offset().top                 }, 1000);                 return false;             }         }     });   I am running jQuery 3.3.1. I have commented out all code in the app.js to identify where the issue may be coming from. This code is right at the top and I have added console.logs all over the document, which show in Console.  What am I doing wrong here?  Thank you!
105378
Use Case:  What i want is a list of records, and allow this user to choose 2 of those records, then click a button to go to a new VF page, if the user selects more than 2, i want him to get a notification of some kind saying you need to select 2 records, I do not want the page refeshed though.  Strategy:  I'm creating a wrapper class for the records like this:  and i have that part going by creating a custonm controller... I need the notification part working.   Problem:  I don't know how to call methods from the customController in javascript Also, i do not want to refresh the entire page. I just want them to go back to where they were. I was thinking a pop-up notification but I'm flexible..
33494
I have the following code making a GET request on a URL:  $('#searchButton').click(function() {     $('#inquiry').load('/portal/?f=searchBilling&amp;pid=' + $('#query').val());             });   But the returned result is not always reflected. For example, I made a change in the response that spit out a stack trace but the stack trace did not appear when I clicked on the search button. I looked at the underlying PHP code that controls the ajax response and it had the correct code and visiting the page directly showed the correct result but the output returned by .load was old.  If I close the browser and reopen it it works once and then starts to return the stale information. Can I control this by jQuery or do I need to have my PHP script output headers to control caching?
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!
113427
I have a (relatively) tricky situation where my code requires changing the loop output every three posts, and within those three posts there are divs around two of the posts.  The code below displays 6 posts and I would want to loop though a total of 24 posts, repeating this four times.  Can anyone help? Thanks!  FIRST THREE  &lt;div class="layer"&gt;  &lt;div class="large left"&gt;     &lt;div class="item"&gt;     &lt;?php the_title(); ?&gt;     &lt;?php the_content(); ?&gt;     &lt;/div&gt;&lt;!--item--&gt; &lt;/div&gt;  &lt;div class="small left"&gt;     &lt;div class="item"&gt;     &lt;?php the_title(); ?&gt;     &lt;?php the_content(); ?&gt;     &lt;/div&gt;&lt;!--item--&gt;      &lt;div class="item"&gt;     &lt;?php the_title(); ?&gt;     &lt;?php the_content(); ?&gt;     &lt;/div&gt;&lt;!--item--&gt; &lt;/div&gt;  &lt;/div&gt;&lt;!--layer--&gt;   SECOND THREE  &lt;div class="layer"&gt;  &lt;div class="small left"&gt;     &lt;div class="item"&gt;     &lt;?php the_title(); ?&gt;     &lt;?php the_content(); ?&gt;     &lt;/div&gt;&lt;!--item--&gt;      &lt;div class="item"&gt;     &lt;?php the_title(); ?&gt;     &lt;?php the_content(); ?&gt;     &lt;/div&gt;&lt;!--item--&gt; &lt;/div&gt;  &lt;div class="large right"&gt;     &lt;div class="item"&gt;     &lt;?php the_title(); ?&gt;     &lt;?php the_content(); ?&gt;     &lt;/div&gt;&lt;!--item--&gt; &lt;/div&gt;  &lt;/div&gt;&lt;!--layer--&gt;
9926
What is the best method in jQuery to add an additional row to a table as the last row?  Is this acceptable?  $('#myTable').append('&lt;tr&gt;&lt;td&gt;my data&lt;/td&gt;&lt;td&gt;more data&lt;/td&gt;&lt;/tr&gt;');   Are there limitations to what you can add to a table like this (such as inputs, selects, number of rows)?