Skip to content

Instantly share code, notes, and snippets.

@ihsanberahim
Created January 2, 2015 09:09
Show Gist options
  • Save ihsanberahim/7497cbe82e57084c8d5e to your computer and use it in GitHub Desktop.
Save ihsanberahim/7497cbe82e57084c8d5e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<p>Please download this jsbin file to make sure it is works</p>
<a href="http://google.com">Google</a>
<script id="jsbin-javascript">
var links = document.querySelectorAll('a');
var onClick = function()
{
/*
Do something;
this.source
this.details.link
*/
console.log(this.source);
console.log(this.details.link);
};
console.log(links);
var key = 0;
while(key < links.length)
{
var link = links[key].getAttribute('href');
//Disable click
links[key].setAttribute('onclick','return false;');
//Bind click callback
links[key].addEventListener('click',onClick.bind({
source: links[key],
details: {
link: link
}
}));
console.log(link);
key++;
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">var links = document.querySelectorAll('a');
var onClick = function()
{
/*
Do something;
this.source
this.details.link
*/
console.log(this.source);
console.log(this.details.link);
};
console.log(links);
var key = 0;
while(key < links.length)
{
var link = links[key].getAttribute('href');
//Disable click
links[key].setAttribute('onclick','return false;');
//Bind click callback
links[key].addEventListener('click',onClick.bind({
source: links[key],
details: {
link: link
}
}));
console.log(link);
key++;
}
</script></body>
</html>
var links = document.querySelectorAll('a');
var onClick = function()
{
/*
Do something;
this.source
this.details.link
*/
console.log(this.source);
console.log(this.details.link);
};
console.log(links);
var key = 0;
while(key < links.length)
{
var link = links[key].getAttribute('href');
//Disable click
links[key].setAttribute('onclick','return false;');
//Bind click callback
links[key].addEventListener('click',onClick.bind({
source: links[key],
details: {
link: link
}
}));
console.log(link);
key++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment