Skip to content

Instantly share code, notes, and snippets.

@cherenkov
Created April 21, 2012 01:11
Show Gist options
  • Select an option

  • Save cherenkov/2433063 to your computer and use it in GitHub Desktop.

Select an option

Save cherenkov/2433063 to your computer and use it in GitHub Desktop.
innerHTMLで挿入するhtmlにもjqueryを実行させたい。 あらかじめ.. - 人力検索はてな http://q.hatena.ne.jp/1334925685
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
jQuery.fn.extend({
hoge: function() {
return this.text('hoge')
}
});
$(function() {
$(document).on('DOMNodeInserted', '#divHoge', function() {
$(this).hoge()
})
/*
$('#divHoge').live('DOMNodeInserted', function() {
$(this).hoge()
})
*/
setTimeout(function() {
document.body.innerHTML = '<div id="divHoge">piyo</div>';
}, 1000);
});
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment