Why jquery have problem with onbeforeprint event?
- by Cesar Lopez
Hi all,
I have the following function.
$(function() {
$(".sectionHeader:gt(0)").click(function() {
$(this).next(".fieldset").slideToggle("fast");
});
$("img[alt='minimize']").click(function(e) {
$(this).closest("table").next(".fieldset").slideUp("fast");
e.stopPropagation();
return false;
});
$("img[alt='maximize']").click(function(e) {
$(this).closest("table").next(".fieldset").slideDown("fast");
e.stopPropagation();
return false;
});
});
<script type="text/javascript">
window.onbeforeprint = expandAll;
function expandAll(){
$(".fieldset:gt(0)").slideDown("fast");
}
</script>
For this html
<table class="sectionHeader" ><tr ><td>Heading 1</td></tr></table>
<div style="display:none;" class="fieldset">Content 1</div>
<table class="sectionHeader" ><tr ><td>Heading 2</td></tr></table>
<div style="display:none;" class="fieldset">Content 2</div>
I have several div class="fieldset" over the page, but when I do print preview or print, I can see all divs sliding down before opening the print preview or printing but on the actual print preview or print out they are all collapse.
I would appreciate if anyone comes with a solution for this.
Anyone have any idea why is this or how to fix it?
Thanks.
PS:Using a does not work either ( I assume because jquery using toggle) and its not the kind of question I am looking for.