Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery inserted HTML is rendered as a raw text

Tags:

People also ask

What is jQuery HTML?

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.

What is parseHTML in JavaScript?

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).

How HTML elements are used in jQuery with example?

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.

How do I get inner text in jQuery?

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 ?