Andrés Girón Andrés Girón - 1 year ago 57
HTML Question

Show hidden div permanently throughout website after clicking on a specific <a> href link once

i found this link of a question like the one i have, the thing is that the solution they give its for clicking any div in the html, and i need something like, when i click the first div, the second div its showed and when i press the second div, the third div its showed, and i need it to keep on localstorage... This is my HTML code:

<div id='btn1' class="col-lg-4"">
<a id="tema_1 " href="tema.html"><img id="img_tema1" class="img-circle" src="../assets/img/primer_tema.gif" alt="Generic placeholder image" width="140" height="140"></a>
<h2>Tema 1</h2>
</div><!-- /.col-lg-4 -->

<div class="col-lg-4-2">
<a href=""><img id="img_tema2" class="img-circle2" src="../assets/img/segundo_tema.gif" alt="Generic placeholder image" width="140" height="140"></a>
<h2>Tema 2</h2>
</div><!-- /.col-lg-4-2 -->

<div class="col-lg-4-3">
<a href="tema_3.html"><img id="img_tema3" class="img-circle3" src="../assets/img/tercer_tema.gif" alt="Generic placeholder image" width="140" height="140"></a>
<h2>Tema 3</h2>
</div><!-- /.col-lg-4-3 --

And this is the example of Jquery code that i use:

var hide2 = localStorage[location] ? false : true;
var hidden2 = document.querySelector('.col-lg-4-2');

if(hide2) { = 'none';
document.onclick = function() {
localStorage[location] = true; = '';
document.onclick = '';

But as i say... it makes that any div that i click, shows the Tema 2, and i need that the only div that can show the Tema 2 is the Tema 1 Div.

Excuse my bad english but my mother language its Spanish.

Thank you for any help.

Answer Source

I think this might be solved using simple jQuery. I've used the example specified at: Previous Similar question and changed it so it will fit your code. It currently works which is fine but I might wanna work around it if you don't like my solution.

 $(function () {
    var showLittleHeader = localStorage.getItem('#second-img');
    if (showLittleHeader) {
    $('#first-img').on('click', function () {
        localStorage.setItem('#second-img', 1);


$(function () {
    var showLittleHeader = localStorage.getItem('#third-img');
    if (showLittleHeader) {
    $('#second-img').on('click', function () {
        localStorage.setItem('#third-img', 1);


Look at this JS Fiddle and see if it does the job for you:

Updated Solution with Local Storage

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download