So basically I have two different HTML pages. I wanted to create a function that when a button on the first html page is clicked, then it will show/hide a div element on the second html.
Can this be done with javascript?
Thanks in advance
So basically I have two different HTML pages. I wanted to create a function that when a button on the first html page is clicked, then it will show/hide a div element on the second html.
Can this be done with javascript?
Thanks in advance
AS @roXon mentioned one option you could do this with HTML5 storage.
E.g.
if(typeof(Storage)!=="undefined")
{
$('#FirstClick').on('click',function(){
localStorage.clickedDiv = $(this).attr('id');
$(this).hide();
});
}
else
{
$(this).hide();
}
Then on the second page.
$(function(){
$(localStorage.clickedDiv).hide();
});
Or for more backward browser support you could use cookies.
I not sure what you mean by second html page, maybe you mean content? With jQuery this can be done... for example...
<script type="text/javascript">
$(document).ready(function(){
$(".slidingDiv").hide();
$(".show_hide").show();
$('.show_hide').click(function(){
$(".slidingDiv").slideToggle();
});
});
</script>
<a href="#" class="show_hide">Show/hide</a>
<div class="slidingDiv">
<a href="#" class="show_hide">hide</a></div>
css
.slidingDiv {
height:300px;
background-color: #99CCFF;
padding:20px;
margin-top:10px;
border-bottom:5px solid #3399FF;
}
.show_hide {
display:none;
}
Maybe you mean to load content on a second page (or interact with it ) see http://api.jquery.com/load/ and question: Load content of a div on another page
If the browser support HTML5 storage you can save a variable http://www.w3schools.com/html/html5_webstorage.asp
Otherwise you'll need to pass a GET parameter or a cookie.