How to dynamically create a ul li with appended text
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 lang="en" xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta charset="utf-8" /> | |
<title></title> | |
<script src="jquery-1.8.2.min.js"></script> | |
<script> | |
var MyArrayData = []; | |
$(document).ready(function () { | |
disp($(".MyData").toArray()); | |
jQuery.each(MyArrayData, function (i, val) { | |
if (val.length) { | |
$('<li />', { html: i }).appendTo('ul.justList') | |
} | |
}); | |
}); | |
function disp(divs) { | |
for (var i = 0; i < divs.length; i++) { | |
MyArrayData.push(divs[i].innerHTML); | |
} | |
} | |
</script> | |
<style> | |
.MyData | |
{ | |
display: none; | |
} | |
</style> | |
</head> | |
<body> | |
<ul class="justList"></ul> | |
<div class="MyData"> | |
One | |
</div> | |
<div class="MyData"> | |
Two | |
</div> | |
<div class="MyData"> | |
Two | |
</div> | |
</body> | |
</html> |