Tag Archives: year

Displaying year on your website with JavaScript and jQuery

In HTML-part:

2016

 
In JavaScript, if the year is the same as the first year (in our example 2016) - we won't display it:
(function() {

			
	var dateNow = new Date();
	var thisYear = dateNow.getFullYear();
	var changeText = document.getElementById("js-year");

	if (thisYear != "2016"){
	
		changeText.innerHTML = ' - ' +thisYear;
	}
})();
 
And in jQuery:
$(document).ready(function(){
			
var dateNow = new Date()
	var thisYear = dateNow.getFullYear();

	if (thisYear != "2016"){
	
		$("#js-year").text(' - ' +thisYear);
	}

			
});