Reputation: 1896
This might seem a little simple, but i've tried many ways & non of them are working as expected.
i have values coming in from an ajax call, & i am displaying these to a <table>
.
the data will not be seen at first (css - display:none
) but onclick
involves a function which displays a dialog of said data.
writing out the data in these ways does not work:
var text = "Example Data<br>";
var text = document.createTextNode("Example Data" + document.createElement('br'));
var text = document.createTextNode("Example Data");
text += document.createElement('br');
The latter outputs [object Text][object HTMLBRElement]
How do i write this correctly??
Upvotes: 0
Views: 1136
Reputation: 73
You can try this:
$('#tableid').html(responsedata);
Upvotes: 0
Reputation: 6014
Try
var p = document.createElement("p");
p.innerHTML = "Example Text<br>";
Upvotes: 0
Reputation: 1688
You need to append the line break
as an HTML element "createElement" as it is an HTML element.
var text = 'test';
var newtext = document.createTextNode(text),
p1 = document.getElementById("p1");
p1.appendChild(newtext);
p1.appendChild(document.createElement('br'));
p1.appendChild(document.createTextNode('newline displayed'));
Upvotes: 0
Reputation: 944568
You can't concatenate node objects (trying to do so with +
will convert them to strings first).
Find the element you want to append the nodes you've created, and call appendChild
on it repeatedly.
var text = document.createTextNode("Example Data");
someElement.appendChild(text);
someElement.appendChild(document.createElement('br'));
Upvotes: 1