Tags


Extract text from a HTML page then build an array using Javascript

jquery.min.js file you can download from here

(https://www.dropbox.com/s/2mm9vzzfuy0510s/jquery.min.js)

1). You can test with this html page

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<script src=”jquery.min.js”></script>

<script type=”text/javascript”>
function htmlarray(){
var array1 = [];

$(“div”).each(function() {
array1.push($.trim($(this).text()));
});

for(var i=0;i<array1.length;i++)

alert(array1[i]);

}
window.onload = htmlarray;
</script>
</head>

<body>
<div class=”elements”>Text</div>
<div class=”elements”>Text 2</div>
<div class=”elements”>Text 3</div>
</body>
</html>

Advertisements