Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting element value within an event callback using jQuery
    text
    copied!<p>A little stumped by this one so I'm hoping you guys can help. </p> <p>Looks like I may have found an IE-related jQuery bug. Created a small test (included here) which I can dupe the issue. Works fine in Firefox and Chrome and fails in IE8-9.</p> <p>Issue is that the DIV "podcastStatus" isn't being updated at the correct moment when the update occurs within an event callback. You can test it locally by using IE tools and Firebug and setting breakpoints where I've commented in the code.</p> <p>Steps:</p> <ol> <li>Set breakpoints in Firebug and IE</li> <li>Dev tools according to my comments in the code</li> <li>Click on either "Next" or "Prev"</li> <li>Text in the DIV should change to either "Next" or "Prev" depending on which button you clicked</li> <li>Text in the DIV should then revert back to "Playing..."</li> </ol> <p>I think it's innerHTML-related but I've tried the innerHTML DIV wrapper trick and no-dice.</p> <p><strong>NOTE: I've used both .text() and .html() with no resolution.</strong> </p> <p>Here's the test case:</p> <pre><code>&lt;body&gt; &lt;style type="text/css"&gt; #podcastStatus { background-color: ButtonHighlight; font-size: 120pt; font-weight: bolder; color: Black; margin: 0 auto; text-align: center; position:absolute; top:0; bottom:0; left:0; right:0; margin:auto; height:200px; width:100%; z-index: 100; } &lt;/style&gt; &lt;div id="podcastStatus"&gt;Playing...&lt;/div&gt; &lt;div id="targetBtns"&gt; &lt;input type="button" name="prev" id="prev" value="Prev"/&gt; &lt;input type="button" name="next" id="next" value="Next"/&gt; &lt;/div&gt; &lt;script&gt; function onButtonClicked(e) { switch (e.target.defaultValue) { case "Next": // Use IE tools or Firebug... //Set breakpoint here. Immediate after this executes, DIV text should be updated to "Prev".... $('#podcastStatus').html("Prev").show(); break; case "Prev": // Use IE tools or Firebug... //Set breakpoint here. Immediate after this executes, DIV text should be updated to "Next".... $('#podcastStatus').html("Next").show(); break; } //Set breakpoint here. DIV should show either "Prev" or "Next" at this point... playPause(); } function playPause() { $('#podcastStatus').text("Playing...").fadeIn('slow'); } $( "#targetBtns" ).click( function(event) { onButtonClicked(event) } ); &lt;/script&gt; &lt;/body&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload