前項のサンプルでも使用しましたが、要素の中身をHTML文字列で返す関数です。
また、引数として文字列を与えた場合、中身をその文字列に更新します。
以下、サンプルソースです。
<html>
<head>
<title></title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load("jquery", "1.3");</script>
<script type="text/javascript">
$(document).ready(function(){
function execute_sample(selector){
if( selector == undefined ){
selector = '#sample';
}
var code = $(selector).html();
eval(code);
}
</script>
</head>
<body>
<input type="button" value="サンプル実行"
onclick="execute_sample('#sample_id')"><br />
<span id="sample_id">alert( $("#target_element").html() );</span><br />
<input type="button" value="サンプル実行" onclick="execute_sample('#sample1')" />
<span id="sample1">alert( $("#sample1").html() );</span><br />
<input type="button" value="サンプル実行" onclick="execute_sample('#sample2')" /><br />
<span id="sample2">$("#sample3").html("文字列を置き換え。");</span><br /><br />
<span id="sample3">ここが変わります。</span>
</body>
</html>
以下、例です。