Category Archives: JavaScript

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);
	}

			
});

Hiding email from spam-bots

In your HTML:

Here is JavaScript's part:




Ok, and now jQuery's version:
emailE=('mail@' + 'mal.com');
var neededDiv =  ('#js-m-pr');
if($(neededDiv)!=null){
 $(neededDiv).html('' + emailE + '');
}

source

arc() method

During Coding Math lessons context.arc() was used and I didn't know which arguments it used. Arc is a section of circle and it's defined by:
  1. x-point
  2. y-point
  3. radius
  4. starting angle
  5. ending angle
  6. direction of the arc
  7. x and y point define the center of the circle. Radius is for the distance from the center point and direction can be clockwise (false) or anticlockwise (true). In this example radius is 10 and last argument is clockwise (false).

    See the Pen arc() method 1) by AnuVi (@AnuVi) on CodePen.

    In this example I changed the anticlockwise to true and radius is 50.

    See the Pen arc() method 2) by AnuVi (@AnuVi) on CodePen.

    More info HTML5 Canvas Arc Tutorial