How to disable all links using jQuery

To disable all links using jQuery you cna use the snippet below.

Samples

jQuery Sample

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to remove class after delay in jQuery

To remove class after delay in jQuery you can use one of the snippet below.

Samples

jQuery Sample using setTimeout()

Samples

jQuery Sample using delay() and queue()

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to select an element with its name attribute in jQuery

To select an element with its name attribute in jQuery you can use the snippet below.

Samples

Javascript Sample

if you remove the div in div[name=”de.Fesslersoft.Testname”] you will get all elements with the specific name.

You can also have a look at this JSFiddle.

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to add or remove a class on hover using jQuery

To add or remove a class on hover using jQuery you can use the snippet below.

Adding a Class

See this JSFiddle for adding a CSS-Class.

$('#test1').hover(function(){  $(this).addClass('hoverClass');});

Removing a Class

See this JSFiddle for removing a CSS-Class.

$('#test1').hover(function(){  $(this).removeClass('hoverClass');});

Please rate this snippet

How to reload or rerender the page using AngularJS

To reload or rerender the page using AngularJS you can use the snippet below.

Sample AngularJS

$route.reload();

Please rate this snippet

How to check if an array contains a value in Javascript

To check if an array contains a value in Javascript you can use the snippet below.

Sample Javascript

Array.prototype.inArray = function (inputValue) {
	var counter;
	for (counter=0; counter < this.length; counter++) {
		if (this[counter] === inputValue) {
			return true;
		}
	}
	return false;
};

Please rate this snippet

How to define global Variables in AngularJs

To define global Variables in AngularJs you can use one of the following ways.

WAY1: Using $rootScope (see this JsFiddle)

HTML:

<div ng-controller="Testfct2">
    <div ng-controller="Testfct">This Website URL is {{name}}!</div>
</div>

Javascript:

var myApp = angular.module('myFesslersoftSampleApp',[]);

function Testfct2($scope, $rootScope) {
    $rootScope.name = 'http://codesnippets.fesslersoft.de';
}

function Testfct($scope, $rootScope) {
    $scope.name = $rootScope.name;
}

WAY2: Using a Service (see this JsFiddle)

HTML:

<div ng-controller="Testfct">
  This Website URL is {{name}}!
</div>

Javascript:

var myApp = angular.module('myFesslersoftSampleApp',[]);
myApp.factory('GlobalVarsService', function() {
    return {
        name : 'http://codesnippets.fesslersoft.de'
    };
});

function Testfct($scope, GlobalVarsService) {
    $scope.name = GlobalVarsService.name;
}

The AngularFAQ is saying:

$rootScope exists, but it can be used for evil
Scopes in Angular form a hierarchy, prototypally inheriting from a root scope at the top of the tree. Usually this can be ignored, since most views have a controller, and therefore a scope, of their own.

Occasionally there are pieces of data that you want to make global to the whole app. For these, you can inject $rootScope and set values on it like any other scope. Since the scopes inherit from the root scope, these values will be available to the expressions attached to directives like ng-show just like values on your local $scope.

Of course, global state sucks and you should use $rootScope sparingly, like you would (hopefully) use with global variables in any language. In particular, don’t use it for code, only data. If you’re tempted to put a function on $rootScope, it’s almost always better to put it in a service that can be injected where it’s needed, and more easily tested.

Conversely, don’t create a service whose only purpose in life is to store and return bits of data.

FOR MORE INFORMATIONS SEE Services, $rootScope

Please rate this snippet