I want to display content in a div whose id is search_result, I am using following code but it is only showing the last element of the array because of innerHTML. Can anyone help me to append the data.
here is my JavaScript code
function myFunction($qw) {
for ($i = 0; $i < data.length; $i++) {
$dis = data[$i].charAt(0);
var $n = ($dis.localeCompare($qw))
if ($n == 0)
document.getElementById("search_result").innerHTML = (data[$i] + "<br/>");
}
$i = 0;
}
Here is my HTML code :
<div id="search_result">
</div>
+=instead of=. You are replacing what is already contained in the element by setting it to a new value every iteration.