jquery insert element after()

86 views Asked by At

I've got the following html:

<pre id="api_result"><code class="json">  
</code></pre>

When I use

$("#api_result").text("some json"));

This leads to the following HTML code:

<pre id="api_result">some json</pre>

I've already tried to use:

$("#api_result").after(("#api_result > code"), "some json");

This doesn't solve the problem of "deletion of thepre too. Where's my fault?

2

There are 2 answers

0
Theo On

How about $("#api_result > code").text("some json");?

0
Loaf On

Try one of these

$("#api_result > .json").text("some json"))
$("#api_result:first-child").text("some json"))