Reputation: 259
I am trying to generate an element from variable in jquery
. My variable is like below:
var panelheader = "<div class='panel panel-default'><div class='panel-heading pnlbld'>Test</div><div class='panel-body'></div></div>"
I want to change panel-heading
text and want to insert in panel-body
.
$(panelheader + '.panel-heading').text('Name')
Above statement removes all divs
inside panel with text Name
. But I want this as panel-heading
.
Also, when I tried to insert table
between panel-body
like below:
$(panelheader + '.panel-body').prepend(mytbl)
It creates table
before panel-heading
.
I want the "Name" to be in the place of "Test" and mytbl
in between
<div class='panel-body'></div>
Upvotes: 0
Views: 75
Reputation: 782785
You need to convert the HTML string in panel-header
into DOM elements, and then do the replacement in that.
var ph = $(panelheader);
ph.find(".panel-heading").text('Name');
$("#somediv").append(ph);
Upvotes: 1