Growler Growler - 2 months ago 8
CSS Question

Apply hidden attribute to span

I'm trying to mimic the way this element is hidden... it doesn't appear there is any css that is applied to the spans to make them hidden:

<span hidden>E</span>


I tried:

var letter = document.createElement('span');
letter.innerHTML = message.split("")[i];
letter.style.display = 'none';


But this does:

<span style="display: none;">E</span>


The
spans
are bare, meaning they don't have any class names associated with them. Meaning, they appear as such:

<span hidden>x</span>
<span hidden>y</span>
<span hidden>z</span>


Is there a way to do this?

Answer

Try this:

var letter = document.createElement('span');
letter.innerHTML = message.split("")[i];
letter.setAttribute("hidden","");