Monaca/DOM操作
提供: 初心者エンジニアの簡易メモ
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>
