-2

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?

Mohammad
  • 21,175
  • 15
  • 55
  • 84
wichtel
  • 181
  • 1
  • 3
  • 16
  • uhm... well, you see, `$("#api_result")` selects the element with `id="api_result"`, if you replace it's content with text, it will no longer have a code element within it... surely you mean to replace the content of the code element instead, no? .after doesn't seem to be relevant to your problem, because you don't seem to be wanting to insert anything after anything else. – Kevin B Jan 03 '17 at 21:00

2 Answers2

-1

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

Theo
  • 885
  • 6
  • 16
-1

Try one of these

$("#api_result > .json").text("some json"))
$("#api_result:first-child").text("some json"))
Loaf
  • 3,011
  • 2
  • 15
  • 25