I am trying to remove html comments(<!-- -->) using jQuery and then use slide or show to make some <article> elements within a div to show up. The reason I am doing this instead of using .hide directly is because when I use .hide the height of the hidden <article>'s is still shown so the container div has empty space below.

Is that possible?

有帮助吗?

解决方案

using jquery uncomment plugin you can remove

here is the library file

library

library code by Romuald Brunet

   (function($) {
    $.fn.uncomment = function(recurse) {
        $(this).contents().each(function() {
            if ( recurse && this.hasChildNodes() ) {
                $(this).uncomment(recurse);
            } else if ( this.nodeType == 8 ) {
                // Need to "evaluate" the HTML content,
                // otherwise simple text won't replace
                var e = $('<span>' + this.nodeValue + '</span>');
                $(this).replaceWith(e.contents());
            }
        });
    };
})(jQuery);

example ---

 <p id="uncomment">
  The <!-- <em>quick</em> brown -->
  fox jumps over the <!-- lazy --> dog <br />
  <a href="#">Click here to reveal <!-- hidden --> comments</a>
</p>
<script type="text/javascript">
$('#uncomment a:last').click(function(e) {
    e.preventDefault();

    $('#uncomment').uncomment(/* recurse */ true );
});
</script>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top