Reputation: 1011
The two functions in the javascript are both having a statement-
$('#'+key).html(data)
funtion data(data) {
$('#'+key).html(data)
}
funtion data2(data) {
$('#'+key).html(data)
}
which is essentially replacing the value of the key. I don't want the replacement but basically add to the same data and then render the new value.
I am very new to Javascript- will be glad if someone can point in the right direction. Thanks in advance.
Upvotes: 0
Views: 234
Reputation: 463
As per first comment of @gurvinder372
funtion data(data) {
$('#'+key).append(data)
}
funtion data2(data) {
$('#'+key).append(data)
}
This will help you to understand data handling on HTML elements using JQuery methods.
Upvotes: 1
Reputation: 4755
Without JQuery:
If you want to add just text, use appendChild
:
function addText(divID, text) {
document.querySelector("#"+divID)
.appendChild(document.createTextNode(text));
}
/** TEST **/
var number = 1;
var intervalID = setInterval(addMore, 500);
function addMore() {
addText("appendHere", "Text #"+(++number)+" ")
// do not add infinitelly
if(intervalID>20)
clearInterval(intervalID);
}
<div id="appendHere"></div>
If you want to append HTML, just alter the code a bit:
function addHTML(divID, html) {
var fragment = document.createElement("span");
fragment.innerHTML = html;
document.querySelector("#"+divID)
.appendChild(fragment);
}
Upvotes: 1
Reputation: 68393
I don't want the replacement but basically add to the same data
Use append
instead of html
$('#'+key).html(data)
funtion data(data) {
$('#'+key).append(data)
}
funtion data2(data) {
$('#'+key).append(data)
}
Upvotes: 2