Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery function attr() doesn't always update img src attribute
    primarykey
    data
    text
    <p>Context: On my product website I have a link for a Java webstart application (in several locations).</p> <p>My goal: prevent users from double-clicking, i. e. only "fire" on first click, wait 3 secs before enabling the link again. On clicking, change the link image to something that signifies that the application is launching.</p> <p>My solution works, except the image doesn't update reliably after clicking. The commented out debug output gives me the right content and the mouseover callbacks work correctly, too.</p> <p>See it running here: <a href="http://www.auctober.de/beta/" rel="nofollow noreferrer">http://www.auctober.de/beta/</a> (click the Button "jetzt starten").</p> <p>BTW: if anybody has a better way of calling a function with a delay than that dummy-animate, let me know.</p> <p>JavaScript:</p> <pre><code>&lt;script type="text/javascript"&gt; &lt;!-- allowClick = true; linkElements = "a[href='http://www.auctober.de/beta/?startjnlp=true&amp;rand=1249026819']"; $(document).ready(function() { $('#jnlpLink').mouseover(function() { if ( allowClick ) { setImage('images/jetzt_starten2.gif'); } }); $('#jnlpLink').mouseout(function() { if ( allowClick ) { setImage('images/jetzt_starten.gif'); } }); $(linkElements).click(function(evt) { if ( ! allowClick ) { evt.preventDefault(); } else { setAllowClick(false); var altContent = $('#jnlpLink').attr('altContent'); var oldContent = $('#launchImg').attr('src'); setImage(altContent); $(this).animate({opacity: 1.0}, 3000, "", function() { setAllowClick(true); setImage(oldContent); }); } }); }); function setAllowClick(flag) { allowClick = flag; } function setImage(imgSrc) { //$('#debug').html("img:"+imgSrc); $('#launchImg').attr('src', imgSrc); } //--&gt; &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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