HTML タグ 変更
今日はhtml()について勉強しましょう。
前、勉強したtext()と似てますが、html()はタグを取得、変更することができます。
html()
html()は text()と似てますが、、、
text()はテキストだけ取得しますが、 html()はタグまで取得します。
$('.class_Name').html('<p>hello</p>');
上のようにタグも入れますね。
では、やってみましょうん。
HTML
<p class="change_greeting">hello</p>
jQuery
$('.change_greeting').html('<b>konnichiha</b>');
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>COREASUR :: jQuery</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.0.min.js" ></script>
<script>
$(function(){
$('.change_greeting').html('<b>konnichiha</b>');
});
</script>
</head>
<body>
<p class="change_greeting">hello</p>
</body>
</html>
こう、pタグをbタグに変更することができます。^^
イメージを入れてみましょうか?
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>COREASUR :: jQuery</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.0.min.js" ></script>
<script>
$(function(){
$('.change_greeting').html("<img src='https://www.coreasur.com/material/images/main/happyCatHeader.png' />");
});
</script>
</head>
<body>
<p class="change_greeting">hello</p>
</body>
</html>
これで終わりです。ありがとうございます。^^