Reputation: 841
I have a script that generates a list of <form>
tags with multiple inputs and buttons inside. I want to use an arrow (↑) on a button but when I write
buttonUp.value="↑";
it doesn't work.
Instead of showing ↑, the button shows the raw code on the page.
How can I make the arrow display on the button?
Upvotes: 3
Views: 10890
Reputation: 118
I don't recommend you do this with JavaScript (for newbies like me it's harder). It's very easy, using only html.
Example:
<input type="submit" value="↑ HELLO" style="border-radius:50px;" />
<button>↑ HELLO</button>
If you still want to use js, the reply from guest271314 is working.
Here is the list of symbols on HTML(click)
PS. I also recommend you use Font Awesome , very nice icons.
Make sure to tell me if worked for you.
I know this doesn't answer your question but I hope this will be useful for newbies
Upvotes: 2
Reputation: 1
Use button
element, which has .innerHTML
property
document.querySelector("button").innerHTML = "↑"
<button></button>
alternatively, use the actual "upwards arrow" or "up arrow" character
document.querySelector("input[type=button]").value = "↑";
<input type="button" value="" />
Upvotes: 1
Reputation: 4997
There is a problem with your solution code--it will only escape the first occurrence of each special character. For example:
escapeHtml('Kip\'s <b>evil</b> "test" code\'s here');
Actual: Kip's <b>evil</b> "test" code's here
Expected: Kip's <b>evil</b> "test" code's here
Here is code that works properly:
function escapeHtml(text) {
return text
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
also u can use below code
function escapeHtml(text) {
var map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}
Upvotes: 0