Skip to content

Instantly share code, notes, and snippets.

@butchi
Last active August 29, 2015 14:09
Show Gist options
  • Save butchi/5ed75fa4909f41e31cf2 to your computer and use it in GitHub Desktop.
Save butchi/5ed75fa4909f41e31cf2 to your computer and use it in GitHub Desktop.
要素からコメントアウトを取り出す ref: http://qiita.com/butchi_y/items/78ef939cbcef4f108c66
<!DOCTYPE html>
<html>
<head></head>
<body>
<!--hoge-->
foo
<!--piyo-->
bar
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
</body>
</html>
var $elm = $('body')
var $comment = $elm.contents().filter(function() {
return this.nodeType === document.COMMENT_NODE;
});
var commentArr = $comment.map(function(i, elm) {
return elm.data;
});
console.log(commentArr);
var $elm = $('body')
var $comment = $elm.contents().filter(function() {
return this.nodeType === document.COMMENT_NODE;
});
$comment.each(function(i, elm) {
console.log(elm.data);
});
<!DOCTYPE html>
<html>
<head></head>
<body>
<!--hoge-->
foo
<!--piyo-->
bar
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="main.js"></script>
</body>
</html>
var $elm = $('body');
var $comment = $elm.contents().filter(function() {
return this.nodeType === document.COMMENT_NODE;
});
$comment.each(function(i, elm) {
console.log(elm.data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment