GettingStarted
GettingStarted

Reputation: 7625

How do I append an HTML string to the DOM

I have a data table with data from a JSON file.

I filtered the data and generated an HTML string that I need prepended to this

 <div class='toolbar'>

I am having issues with prepending it.

 $(document).find(cleanKey).prepend(htmlString) // didnt work

 $('#' + key.toLowerCase().replace(/\s/g, "-") + '-table').prepend(htmlString) // didnt work

Upvotes: 0

Views: 35

Answers (2)

Tony
Tony

Reputation: 3068

You can append a string with the following:

$('#' + key.toLowerCase().replace(/\s/g, "-") + '-table').html() += htmlString; 

Upvotes: 0

Cesar Bielich
Cesar Bielich

Reputation: 4945

Are you prepending or appending?

Prepend

$('.toolbar').prepend(htmlString);

Append

$('.toolbar').append(htmlString);

Upvotes: 1

Related Questions