Alex N
Alex N

Reputation: 1121

how to stop changing the code?

Good day.

I have this code:

<div class="align-center">
 <a href="#" class="client">
  <div><img src="./client0.png" alt="" /></div>
  <p class="italic comm"> Test Test Test Test</p>
</a>
</div>

I paste this code in a textarea ckeditor, but after pressing the tab "source" and back to view page I get changed code:

<div class="align-center">
 <div>
 <a class="client" href="#"><img alt="" src="./client0.png" /></a>
 </div>    
 <p class="italic comm"><a class="client" href="#"> Test Test Test Test</a></p>
</div>

Please tell me how to stop changing the code?

Upvotes: 0

Views: 668

Answers (1)

oleq
oleq

Reputation: 15895

The reason for such behavior is that your markup is invalid.

HTML 4.01 specification (also xHTML 2.0) doesn't allow block elements like <div> inside <a> (see this answer). CKEditor follows those specs so, of course, it also finds your code invalid. Still, CKEditor's parser tries to fix your HTML and the result is what you call "changed code".

Your code could be valid in HTML5 though. CKEditor doesn't support HTML5 DTD yet because it's complex and dynamic as opposed to HTML 4.01 (xHTML 2.0).

At the moment, the only solution is to change your code.

Upvotes: 2

Related Questions