How to put degree character in html input field via javascript
I have a textbox like
Html
<input type="text" id="lat" placeholder="Latitude" ng-lat value="9°">
which works great as it displays the power sign fine, but when I try to set the value via jquery like
Jquery
$("#lat").val("9°")
Displays all text instead of the degree symbol.
+3
source to share
6 answers
$("#test").click(function(){
$("#lat").val("29" + ascii(176))
});
function ascii (a) { return String.fromCharCode(a); }
Updated JSFiddle for further help: http://jsfiddle.net/zkh2of12/1/
+1
source to share
How can I simply set a symbol directly in JavaScript instead of HTML code?
$(function(){
$("#set").click(function(){
$("#lat").val("°");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="lat" placeholder="Latitude" ng-lat value="9°">
<button id="set">set</button>
If you want to improve, just create the hidden <span>
html code you like inside and then just select the html using JavaScript. This will work even for symbols that you cannot post to JS
0
source to share