1

I want to set placeholder with special characters for an input. Thus, this is my code:

input.attr('placeholder', '●●●●●');

This outputs special char codes instead of special characters. What is the correct way to display special characters in input elements using Javascript?

2 Answers 2

2

<input> elements use plain text, not html, so don't overcomplicate your life :)

Just:

input.placeholder="●●●●●";
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much @nicael! Will accept the answer in 10 mins.
@Bravo And edited to provide even more simpler way :)
Thank you once again! That looks very clean!
1

Just use HTML interpreter for the same,

var d = document.createElement("div");
d.innerHTML = "&#9679;&#9679;&#9679;&#9679;&#9679;";
input.setAttribute("placeholder", d.innerText);

3 Comments

Main problem as far as I understand is that placeholder was showing &#9679;&#9679;&#9679;&#9679;&#9679; instead of ●●●●●
Ah, got it. But it is far too complicated. Inputs use plain text, so there's a much simpler way to achieve this task.
this creates new div not in DOM, unless I append it as child to any element in DOM it won't be live in page. also it takes care of the fact that HTMLCodes might be coming from some service

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.