Last active
November 1, 2019 08:04
-
-
Save itochan/6a8c4b95c0ab786f825350e549a48d29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>演習5-1 配列操作とHTMLの一括操作</title> | |
<script src="ex05-1.js"></script> | |
</head> | |
<body> | |
<input type="button" value="数える" onclick="countElements();"> | |
<input type="button" value="倍" onclick="doubleElements();"> | |
<ol id="list"> | |
<li>liタグだよ</li> | |
</ol> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countElements() { | |
var elements = document.getElementsByTagName("li"); | |
alert(elements.length); | |
} | |
function doubleElements() { | |
var elements = document.getElementsByTagName("li"); | |
var length = elements.length; | |
var list = document.getElementById("list"); | |
var element = "<li>liタグだよ</li>"; | |
list.innerHTML = ""; | |
for(var i = 0; i < length * 2; i++) { | |
list.innerHTML += element; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment