「Monaca/DOM操作」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「 ==html書き換え== index.html <head> <script> document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() {...」) |
(→html書き換え) |
||
| 行11: | 行11: | ||
</head> | </head> | ||
<body onload="init();" id="stage" class="theme"> | <body onload="init();" id="stage" class="theme"> | ||
| − | + | <div class="helloclass1">Helloclass1</div> | |
| − | + | <div id="helloid1">Helloid1</div> | |
main.js | main.js | ||
| 行25: | 行25: | ||
}; | }; | ||
</pre> | </pre> | ||
| + | |||
==タグ内のidのtext取得== | ==タグ内のidのtext取得== | ||
<pre> | <pre> | ||
2020年5月22日 (金) 11:36時点における版
html書き換え
index.html
<head>
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("PhoneGap is ready");
}
</script>
</head>
<body onload="init();" id="stage" class="theme">
Helloclass1
Helloid1
main.js
function init() {
document.addEventListener("deviceready", deviceInfo, true);
}
var deviceInfo = function() {
document.getElementById("helloid1").innerHTML = "Helloid2";
document.getElementsByClassName("helloclass1").innerHTML = "helloclass2";
console.log("hello=" + document.getElementById("helloid").innerHTML);
};
タグ内のidのtext取得
<p id="hello1">Hello1</p>
<script>
console.log(document.getElementById("hello1").textContent); // Hello1
</script>
タグ内のclassのtext取得
<p class="hello2">Hello2</p>
<script>
console.log(document.getElementsByClassName("hello2").textContent); // Hello1
</script>
