トップページ >  Ajax >  jQueryの基本的な関数 html()
初版2009/08/11: 最終更新日2009/08/11
jQueryの基本的な関数 html()
目次
jQueryの基本的な関数 html()
サンプルソース
実行例1
実行例2
jQueryの基本的な関数 html()
前項のサンプルでも使用しましたが、要素の中身を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>
実行例1
以下、例です。



alert( $("#sample1").html() );

実行例2
以下は、html()関数に引数を渡した時の実行例です。



$("#sample3").html("文字列を置き換え。");

ここが変わります。
Information
リンクについて
個人情報保護方針
Yahoo!ブックマークに登録

社長ブログ
やる気はあるがお金がない㈱コンフレッジブログ

広告
株式会社グローハウジング


サイト内検索
当サイト内を検索できます↓


PV