Display values of Array with a Loop

[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sorting</title>
<script type=’text/javascript’ src=’http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver=3.2.1′></script>

<script type="text/javascript">
$(‘document’).ready(function () {

var arr = [52, 97, 3, 62, 10, 63, 64, 1, 9, 3, 4];

for (i = 0; i < arr.length; i++) {
$(‘p#test’ + i).html(arr[i]);
}

});

</script>
</head>
<body>
<h1>This is a sorting example</h1>
<p id="test0">test</p>
<p id="test1">test</p>
<p id="test2">test</p>
<p id="test3">test</p>
<p id="test4">test</p>
<p id="test5">test</p>
<p id="test6">test</p>
<p id="test7">test</p>
<p id="test8">test</p>
<p id="test9">test</p>
<p id="test10">test</p>
<div><input type="button" value="sort" id="sortButton" /></div>
</body>
</html>
[/html]

Leave a Reply