Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Sample code using data-* attributes to call click functions.

Notifications You must be signed in to change notification settings

tmbtech/data-clickevent-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Data-* Click Event, Sample Code

Sample code using data-* attributes to call click functions.

var funcs = {
	click1: function () {
		console.log('click1!!!');
	},
	click2: function () {
		console.log('click2!!!');
	}
};

function executeFunctionByName(functionName, context) {
	var args = [].slice.call(arguments).splice(2);
	var namespaces = functionName.split(".");
	var func = namespaces.pop();
	for (var i = 0; i < namespaces.length; i++) {
		context = context[namespaces[i]];
	}

	context[func].apply(this, args);
}


$(function () {
	$('a[data-trigger]').on('click', function () {
		var action = $(this).data('trigger');
		executeFunctionByName(action, funcs);
	});
});

About

Sample code using data-* attributes to call click functions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published