Reputation: 1993
HTML :
<button id="hide_some_text">Hide</button>
<div id="first">my name is Sea Mist and iam 19 years old</div>
<div id="second" style="display: none">This is the hidden text to be printed and selected only when button is pressed</div>
JQUERY :
$("#hide_some_text").click(function(){
$("#second").toggle();
});
What i want :
If text under div tag "second" is visible only then it should be SELECTED and PRINTABLE (PLZ note im working in IE) , if text under div tag "second" is hidden then it should not get SELECTED when i do a Ctrl+A -> Ctrl + V and also should not be displayed when i go for Print Preview
Note : im using IE , these problems dont occur in mozzila or chrome , but due to constraints i have to use IE so i need a IE specific solution
Upvotes: 2
Views: 132
Reputation: 26878
Do something like this in your JavaScript:
var cache;
$("#hide_some_text").click(function(){
if($("#second").is(":visible")) { //if it's not hidden
cache = $("#second").html(); //cache the HTML
$("#second").hide().html(""); //hide and empty HTML
}
else { //else, it's hidden
$("#second").show().html(cache); //show and get back HTML
}
});
$(document).ready(function() {
$("#hide_some_text").click();
});
Upvotes: 2