Hi Everyone,
I am trying to store the state of a show/hide button so that when the browser is refreshed it will show the previous stored state.
I have a working solution for this on a JS fiddle https://jsfiddle.net/knetdk82/7/
However the issue I have is I cannot apply it in my jQuery library. After doing a test by alerting the text I am storing, I am only ever storing a true value no matter if the area I am trying to hide is showing or not.
Here is my code. Any help understanding why :visible is always true in my below code and how to fix it would be great.
// This is how the function is called in my main HTML file. .sh is my button and area is the areas which are being toggled.
$('.sh').multiButtonClick({area: ['.firstpara', 'img.graphic'] ,speed: 'medium', tog: 'parent', store: 'my test'});
//the html setup of the divs and button are as below
<div class="innercontainer">
<h2>text <button class="sh">show/hide</button></h2>
<p class="firstpara">
text goes here
</p>
</div>
// This is the relevent part of my library
(function( $ ) {
$.fn.multiButtonClick = function (settings) {
var defaults = {
area : 'p',
speed : 'slow',
tog : 'parent',
store: 'my test'
};
var settings = $.extend({}, defaults, settings);
else if (settings.tog == 'parent')
{
return $(this).click(function() {
$(this).parent().nextAll(settings.area).toggle(settings.speed);
localStorage.setItem(settings.store, $(".innercontainer").siblings().is(":visible"));
alert($(".innercontainer").siblings().is(":visible"));
});
var set = localStorage.getItem(settings.store);
if (set == 'true') {
$(settings.area).show()
}
else{
$(settings.area).hide()
}
}
}
Thanks,
Piers