Salvar "addClass" com Session Storage html5
Boa tarde!
Estou desenvolvendo uma aplicação web e estou com uma dúvida, não estou conseguindo fazer um script para salvar o valor setado no addclass, encontrei um exemplo: https://www.inkling.com/read/jquery-cookbook-cody-lindley-1st/chapter-17/recipe-17-2, porém não consegui adaptá-lo... alguém pode me ajudar.
[inline]<!DOCTYPE html>
<html><head>
<title>17.2 Saving Application State for a Single Session</title>
<style>
.square {
width: 100px; height: 100px; margin: 15px;background-color: gray; border: 3px solid white; }
.selected {
border: 3px solid orange; }
</style>
<script src="../../jquery-1.3.2.min.js"></script>
</head>
<body>
<h1>17.2 Saving Application State for a Single Session</h1>
<a href="one.html">page one</a>
<a href="two.html">page two</a>
<div id="one" class="square"></div>
<div id="two" class="square"></div>
<div id="three" class="square"></div>
</body></html>[/inline]
[inline]jQuery(document).ready(function() {$('.square').each(function(){if( sessionStorage[window.location + this.id] == 'true' ) {$(this).addClass('selected');}});$('.square').click(function() {$(this).toggleClass('selected');sessionStorage[window.location + this.id] = $(this).hasClass('selected');return false;});});[/inline]Discussão (2)
Carregando comentários...