0

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>
2
  • 2
    $(panelheader).find('.panel-heading').text('Name') and same for panel-body Commented Oct 16, 2015 at 15:01
  • In addition to the above you need to do $(panelheader).find('.panel-body').html(myTbl) to put your table as the content of panel-body Commented Oct 16, 2015 at 15:04

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.