javascript - How to dynamically create mixed HTML content in jQuery -


considering want create html dynamically:

<li><img src="a"/>some text</li> 

some text text string potentially unsafe, let's stored in variable 'some_text'.

the idea call $('<li>').append($('<img>').attr({src:"a"}), ... );

using $(some_text) bad idea because it's unsafe.

using text(some_text) doesn't work because text not child of element.

i not want wrap text <span>

i not want invent/use function sanitizes or escapes string

there many ways, possibly simplest first add text content li element , prepend image correct order.

$('<li>').text(some_text).prepend($('<img>').attr({src:"a"}), ... ); 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -