jQuery is a lightweight, "write less, do more", JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.
parseHTML uses native methods to convert the string to a set of DOM nodes, which can then be inserted into the document. These methods do render all trailing or leading text (even if that's just whitespace).
The html() method in jQuery is used to get the contents of the first element in the set of matched elements or is used to set the HTML contents of every matched element. It returns the content of the first matched element.
Answer: Use the jQuery text() method You can simply use the jQuery text() method to get all the text content inside an element. The text() method also return the text content of child elements.
I have weird situation, I have that string
lorem<br/><br/>ipsum<br/><br/>a<br/>b<br/><br/>c
which is put into a div:
$('div.desc').html(that_string);
or
$('div.desc').html($.parseHTML(that_string));
but in both cases it is being rendered as a raw text:
lorem<br/><br/>ipsum<br/><br/>a<br/>b<br/><br/>c
instead of
lorem
ipsum
a
b
c
Why ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With