I am working on a project involving Javascript and I need a string to be underlined. The code has the word "Date" in front of the current date (represented by the variable now
). The current date needs to be underlined, not the word "Date".
This is the code I am using:
var now = new Date();
document.getElementById('date').innerHTML = "Date " + (now.getMonth()+1)+ "/"+ now.getDate()+ "/"+ now.getFullYear();
I am working on a project involving Javascript and I need a string to be underlined. The code has the word "Date" in front of the current date (represented by the variable now
). The current date needs to be underlined, not the word "Date".
This is the code I am using:
var now = new Date();
document.getElementById('date').innerHTML = "Date " + (now.getMonth()+1)+ "/"+ now.getDate()+ "/"+ now.getFullYear();
How can I do this?
Share Improve this question edited Jun 22, 2017 at 20:38 Christian Sirolli asked Dec 24, 2016 at 16:46 Christian SirolliChristian Sirolli 2601 gold badge6 silver badges19 bronze badges1 Answer
Reset to default 4When something with the ID of "date" is found...
Use CSS for presentation:
#date {text-decoration: underline;}
Snippet
var now = new Date();
document.getElementById('date').innerHTML = "Date <span>" + (now.getMonth()+1)+ "/"+ now.getDate()+ "/"+ now.getFullYear() + "</span>";
#date span {
text-decoration: underline;
}
<div id="date"></div>
Also, please note, there should not be any duplication of id
s. So if there are multiple date
elements in the same page, use class
instead and style this way:
.date {text-decoration: underline;}
Preview