Created
July 23, 2011 14:47
-
-
Save sbp/1101506 to your computer and use it in GitHub Desktop.
Show and hide comments, using jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
button.showComments { margin-right: .5em } | |
.comment { font: inherit; white-space: pre-wrap; color: #ccc } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p><button class="showComments">Show Comments</button> | |
<!-- Example --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create button.showComments to interface | |
// Style .comment for flavour | |
function showComments() { | |
$('*').contents().filter(function() { | |
return this.nodeType == 8; | |
}).each(function(i, e) { | |
pre = $('<pre class="comment"></pre>'); | |
$(e).after(pre); | |
pre.text(e.nodeValue.replace(/^[ \t\r\n]+/, '')); | |
// pre.wrap('<details></details>'); | |
// $('<summary><!-- --></summary>').insertBefore(pre); | |
}); | |
$('button.showComments').text('Hide Comments').click(hideComments); | |
} | |
function hideComments() { | |
$('pre.comment').remove(); | |
$('button.showComments').text('Show Comments').click(showComments); | |
} | |
$(function() { | |
$('button.showComments').click(showComments); | |
}); |
hi
hhhhhh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The "fiddle" filenames are to enable the preview of this code on jsFiddle.