Search code examples
htmlckeditorstrip

CKEDITOR stripping the anchor tag inside a button


I have a piece of html code like this

<button class="login_btn"><a href="#">Login</a></button>

But when I apply CKEDITOR inline editor, it turns to

<button class="login_btn">Login</button>

I tried using

config.allowedContent = true;

and

config.extraAllowedContent = 'button(*){*};a(*){*};';

but the issue still persists. I do not want anything to be stripped.


Solution

  • CKEditor is stripping <a> from <button> because a <button> cannot contain an <a> element. Check your HTML with the HTML validator.

    From the html5 button spec:

    there must be no interactive content descendant.

    And the interactive content page lists the anchor tag <a> as the first example.