It depends on your DOM structure.
You want to hide every top level node (and therefore their children) with CSS ( display: none), except for the object you want to print, and every parent element of the specified element (i.e. t want to hide the top level node containing the element you want to print).
() javascript - jQuery .
- , , , 'printThis'
- BODY ,
display: none, 'doNotPrint' - , ( 'printThis')
- DOM , , , (, , hide )
, - , :
$('body').children().addClass('doNotPrint')
function showItem($node) {
$node.removeClass('doNotPrint');
$node.siblings().addClass('doNotPrint')
if($node.parent().length){
showItem($node.parent());
}
}
showItem($('.printThis'));
CSS :
.doNotPrint {display: none;}