Figcaption doesn't accept <a></a> as a child using appendChild()

Hello,
how can I add <a> tag as a child of <figcaption>.
I have tried many solutions, but it didn’t work.
I was able to add e.g. text using createTextNode().

const figCaption is a parent.

Demo:

    // WORKING: Added for test, txt will be added as part of figcaption
            const txt = document.createTextNode('TEST');
            figCaption.appendChild(txt);

            // NOT WORKING
            const a = figCaption.appendChild(
                DOM.create('a', { contentEditable: true }, data.credits)
            );

            // NOT WORKING
            const a = document.createElement('a');
            figCaption.appendChild(a);

What’s more if I return the var figCaption it looks correctly:
JS var:

<figcaption>
<a>Credit text</a>
</figcaption>

but in the DOM <a> is sibling of <figcaption>.
DOM:

<figcaption>
</figcaption>
<a>Credit text</a>

Try giving <a> a class or ID name, then use that name for appendChild. I don’t think it accepts tags alone.

1 Like

shrug works for me… (other than the part where i tried to append to the document instead of the body)…


DOM:
image

2 Likes

Thank you for your time.
I’m using TinyMCE 4, one function in this library caused that figcaption behave as sibling in the DOM.
That’s all. :slight_smile:

1 Like

Thanks. :slight_smile:
A function in TinyMCE 4 caused the behavior in the DOM.

1 Like