Generate HTML in JQuery using Append() -


is there way jquery generate html in page source? trying add anchor tags each row not link since snippet not generate html. thanks!

> link previous question

   $.get('file.txt', function(data) {     var = 0;        var lines = data.split("\n");     $.each(lines, function(n, elem) {     var elements = elem.split(',');       $('#display').append('<div><img src="' + elements[0] + '"/></div>');              });         }); 

yes, jquery way following:

$('<div/>', {   'html': $('<img/>', {     'src': 'http://placehold.it/100x100'   }),   'class': 'some-class-name',   'data-attr': 'custom data attribute' }).appendto('#display'); 

demo: https://jsfiddle.net/6jqds8gx/


Comments