V
V
Vadim Efremov2016-09-25 18:59:21
JavaScript
Vadim Efremov, 2016-09-25 18:59:21

How to hide div on click and remember in cookies?

Hello.
There is a script that, when you click on the link, hides the div and writes to cookies
EVERYTHING WORKS !!! But there is a huge problem.
You need 100-200 such links - If you add a script to each div, you get a huge code
QUESTION How can I reduce this script?

<div class="col" id="box1">
<a id="url1" href="#" target="_blank">ССЫЛКА1</a>
</div>

<script type="text/JavaScript"> 
  $(document).ready(function (){ 
  var box1 = $.cookie('box1')//Получаем значение куки 
  if(box1 =='none'){//Делаем проверку 
  $('#box1').remove();//И закрываем блок если куки есть 
  } 
  $('#url1').click(function() {//При клике на id кнопки закрытия 
  $('#box1').slideUp(1000);//Закрываем сам id блока 
  $.cookie('box1', 'none', { expires: 7});//И создаём куку 
  }); 
  }); 
  </script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Filippenko, 2016-09-25
@alexfilus

You can reduce the script using loops, arrays, and selectors by class or attribute, and not by ID.
Is the "col" class only used for hidden blocks?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question