Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery localStorage clipboard
    primarykey
    data
    text
    <p>i'm studying jquery with localStorage and want to create somekind of page clipboard tab where you can add product, pictrures etc. to view it later.</p> <p>This is my jquery code:</p> <pre><code>var count = 0; jQuery('.add_rem').click(function(e) { e.preventDefault(); if(jQuery(this).hasClass('remove')) { count -= 1; }else { count += 1; } jQuery.each( function(){ if(jQuery(this).hasClass('remove')){ if(count == 0) { jQuery('.list li.empty').show(); } if($(".remove").attr('id') == localStorage.getItem('id') ) { localStorage.removeItem('id'); $("#"+localStorage.getItem('id')).removeClass('remove'); } } else { jQuery('.list li.empty').hide(); localStorage.setItem('count', count); localStorage.setItem('id', jQuery(this).attr('id')); if(jQuery(this).attr('id') == localStorage.getItem('id')){ jQuery(".add_rem#"+localStorage.getItem('id')).addClass("remove"); } localStorage.setItem('link', jQuery('.link').attr('href')); localStorage.setItem('photo', jQuery('.photo').attr('src')); localStorage.setItem('name', jQuery('b.name').text()); jQuery('#hp-content .wrapper .list').append('&lt;li&gt;&lt;a href="'+ localStorage.getItem('link') +'"&gt; &lt;img src="'+ localStorage.getItem('photo') +'" alt="photo" /&gt;&lt;br /&gt;'+ localStorage.getItem('name') +' &lt;/a&gt;&lt;/li&gt;'); jQuery('.panel2 a span').text('('+ localStorage.getItem('count') +')'); } jQuery('.panel2 a span').text('('+ localStorage.getItem('count') +')'); }) }) </code></pre> <p>This is the HTML code of one product:</p> <pre><code>&lt;tr&gt; &lt;td class="nul"&gt; &lt;a href="javascript:;" class="add_rem"&gt;&lt;img src="/img/check_of.png" alt="Add / remove from clipboard" title="add to clipboard"&gt;&lt;/a&gt; &lt;/td&gt; &lt;td class="nul"&gt; &lt;a href="13/test/" class="link"&gt; &lt;img class="photo" alt="Test" src="images/pl/brak.gif"&gt; &lt;/a&gt; &lt;/td&gt; &lt;td class="nul"&gt;&lt;b&gt;Test1 / kk&lt;/b&gt;&lt;/td&gt; &lt;td class="nul"&gt;&lt;i&gt;Princeton&lt;/i&gt;&lt;/td&gt; &lt;td class="nul"&gt;College&lt;/td&gt; &lt;td class="nul"&gt; &lt;a href="13/test/"&gt; &lt;img alt="Show" src="images/general/show.gif"&gt; &lt;/a&gt;&amp;nbsp;&amp;nbsp; &lt;/td&gt; &lt;/tr&gt; </code></pre> <p>This is HTML of clipboard:</p> <pre><code>&lt;div style="" id="clipboard"&gt; &lt;div class="panels"&gt; &lt;ul&gt; &lt;li class="panel2"&gt;&lt;a href="#"&gt;Clipboard &lt;span&gt;(0)&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="hp-content"&gt;&lt;div id="clipboard-bg"&gt; &lt;div class="wrapper"&gt; &lt;ul class="list"&gt; &lt;li class="empty"&gt;&lt;strong&gt;Empty.&lt;/strong&gt;&lt;span class="one"&gt;The clipboard is now empty.&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>but after page reload all copied elements are erased</p> <h2><a href="http://jsfiddle.net/pLPuW/4/" rel="nofollow">JSFIDDLE EXAMPLE</a></h2>
    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