Note that there are some explanatory texts on larger screens.

plurals
  1. POHighlight individual characters and then refreshing the screen to ONLY those characters
    primarykey
    data
    text
    <p>I am new to Javascript (but I like it so far!) and I have a pretty basic little project I'm working on. One component requires me to select characters and then click a button and refresh the screen with JUST the ones that are highlighted. I got the highlighting functionality working using Jquery but I'm wondering about the refresh component. Whats the best way to approach this?</p> <p>EDIT: I guess I should provide a few more details. This list of characters could potentially be very long. Like a few hundred or more. Also after somebody clicks and highlights the characters two things need to happen when they click submit. One the database needs to be informed which characters were highlighted and keep a tally (this is the reason I tagged each span with a unique ID), and two the screen needs to refresh with just the highlighted characters shuffled into random order. </p> <p>So I think what I'm looking for is a way to capture these highlighted characters into a JSON array. Then I can forward the information to the server, process it, and reload the screen with the new (smaller) list shuffled. This process could potentially repeat.</p> <p>Does that help inform design decisions? I'm not sure how to use java script to capture the highlighted characters.</p> <pre><code>&lt;HTML&gt; &lt;HEAD&gt; &lt;script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;style type="text/css"&gt; span.highlight {background-color: #FFFF00;} &lt;/style&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $("body").on("click",".letter", function () { var $this = $(this); $this.addClass("highlight"); }); }); &lt;/script&gt; &lt;/HEAD&gt; &lt;BODY&gt; &lt;span class="letter" id="A"&gt;A&lt;/span&gt; &lt;span class="letter" id="B"&gt;B&lt;/span&gt; &lt;span class="letter" id="C"&gt;C&lt;/span&gt; &lt;span class="letter" id="D"&gt;D&lt;/span&gt; &lt;span class="letter" id="E"&gt;E&lt;/span&gt; &lt;span class="letter" id="F"&gt;F&lt;/span&gt; &lt;span class="letter" id="G"&gt;G&lt;/span&gt; &lt;span class="letter" id="H"&gt;H&lt;/span&gt; &lt;span class="letter" id="I"&gt;I&lt;/span&gt; &lt;span class="letter" id="J"&gt;J&lt;/span&gt; &lt;span class="letter" id="K"&gt;K&lt;/span&gt; &lt;span class="letter" id="L"&gt;L&lt;/span&gt; &lt;span class="letter" id="M"&gt;M&lt;/span&gt; &lt;span class="letter" id="N"&gt;N&lt;/span&gt; &lt;span class="letter" id="O"&gt;O&lt;/span&gt; &lt;span class="letter" id="P"&gt;P&lt;/span&gt; &lt;span class="letter" id="Q"&gt;Q&lt;/span&gt; &lt;span class="letter" id="R"&gt;R&lt;/span&gt; &lt;span class="letter" id="S"&gt;S&lt;/span&gt; &lt;span class="letter" id="T"&gt;T&lt;/span&gt; &lt;span class="letter" id="U"&gt;U&lt;/span&gt; &lt;span class="letter" id="V"&gt;V&lt;/span&gt; &lt;span class="letter" id="W"&gt;W&lt;/span&gt; &lt;span class="letter" id="X"&gt;X&lt;/span&gt; &lt;span class="letter" id="Y"&gt;Y&lt;/span&gt; &lt;span class="letter" id="Z"&gt;Z&lt;/span&gt; &lt;input type="button" onclick="Reduce()" value="Remove Non Highlighted Chars"&gt; &lt;/BODY&gt; &lt;/HTML&gt; </code></pre>
    singulars
    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