Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery element manipulation won't refresh the element
    primarykey
    data
    text
    <p>I've written a jQuery plugin for practice which was supposed to work like <a href="http://unwrongest.com/projects/airport/" rel="nofollow">"Airport" by unwrongest</a>.</p> <p><strong>Short description of how it should operate</strong></p> <ol> <li>Get the text of some element, iterate through it.</li> <li>For every char found, iterate through the alphabet, comparing the char with each char in the alphabet... </li> <li>...until text-char = alphabet-char (or until the "alphabet"-array has no more elements.</li> <li>While comparing, change the actual text with a certain delay.</li> </ol> <p>So for example, using the plugin on hi would change the word from hi (start) to ai, bi, ci, [...], ha, hb, hc, hd, [...], hi, sort of flipping through it. Again, if you have no clue what I mean, you could check the link.</p> <p><strong>Problem</strong></p> <p>Checking the console with firebug, it does change the target text, <strong><em>but it just doesn't update till it has reached the end</em></strong>. First I thought it didnt do anything at all, but when I change the code to turn each character into an "A" (as an example), it updates the text to "AAAAAAAA" at the very end. What I need the plugin to do, though, is of course update it after every single change.</p> <p><strong>The code</strong></p> <pre><code>(function( $ ){ $.fn.myAirport = function() { var text = this.text(); var length = text.length; var alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "!", "?"]; var possibilities = alphabet.length; function changeCharAt(string, index, char) { var length = string.length; if(index &gt; length-1) return string; var before = string.substr(0,index); var after = string.substr(index+1); result = before + char + after; return result; } for (var i = 0; i &lt; length; i++) { var letter = text[i]; console.log("looking for: "+letter); for (var j = 0; j &lt; possibilities; j++) { var test = alphabet[j]; if (letter == test) { console.log("Done, "+letter+" (letter # "+i+") is # "+j+" in the Alphabet-string"); j = possibilities; } else {} text = changeCharAt(text, i, test); $(this).text(text).delay(100); console.log("Trying "+$(this).text()); } } }; })( jQuery ); </code></pre> <p>The plugin is called like this: <code>$("#element").myAirport();</code></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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