Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

deleted 153 characters in body
Source Link
Sarfraz
  • 383.5k
  • 81
  • 561
  • 613

Missing quotes here:

if(href.indexOf(read_today) != -1) 

Should be:

if(href.indexOf('read_today') != -1) 

Also change:

link.setAttribute('onclick', 'alert("Okay")');

To:

link.setAttribute('onclick', function(){ alert("Okay") });

Overall, this is what you should have:

var ourdomainname = "ourdomain.com";
function linkallthelinks(domain) {
 var links = document.getElementsByTagName("a");
 for (var i = 0; i < links.length; i++) {
 var link = links[i];
 var href = link.getAttribute("href");
 if (href.indexOf('read_today') != -1) {
 link.setAttribute('onclick', function(){ alert'alert("Okay") }');
 }
 }
}
//function call
linkallthelinks(ourdomainname);​

Missing quotes here:

if(href.indexOf(read_today) != -1) 

Should be:

if(href.indexOf('read_today') != -1) 

Also change:

link.setAttribute('onclick', 'alert("Okay")');

To:

link.setAttribute('onclick', function(){ alert("Okay") });

Overall, this is what you should have:

var ourdomainname = "ourdomain.com";
function linkallthelinks(domain) {
 var links = document.getElementsByTagName("a");
 for (var i = 0; i < links.length; i++) {
 var link = links[i];
 var href = link.getAttribute("href");
 if (href.indexOf('read_today') != -1) {
 link.setAttribute('onclick', function(){ alert("Okay") });
 }
 }
}
//function call
linkallthelinks(ourdomainname);​

Missing quotes here:

if(href.indexOf(read_today) != -1) 

Should be:

if(href.indexOf('read_today') != -1) 

Overall, this is what you should have:

var ourdomainname = "ourdomain.com";
function linkallthelinks(domain) {
 var links = document.getElementsByTagName("a");
 for (var i = 0; i < links.length; i++) {
 var link = links[i];
 var href = link.getAttribute("href");
 if (href.indexOf('read_today') != -1) {
 link.setAttribute('onclick', 'alert("Okay")');
 }
 }
}
//function call
linkallthelinks(ourdomainname);​
added 553 characters in body
Source Link
Sarfraz
  • 383.5k
  • 81
  • 561
  • 613

Missing quotes here:

if(href.indexOf(read_today) != -1) 

Should be:

if(href.indexOf('read_today') != -1) 

Also change:

link.setAttribute('onclick', 'alert("Okay")');

To:

link.setAttribute('onclick', function(){ alert("Okay") });

Overall, this is what you should have:

var ourdomainname = "ourdomain.com";
function linkallthelinks(domain) {
 var links = document.getElementsByTagName("a");
 for (var i = 0; i < links.length; i++) {
 var link = links[i];
 var href = link.getAttribute("href");
 if (href.indexOf('read_today') != -1) {
 link.setAttribute('onclick', function(){ alert("Okay") });
 }
 }
}
//function call
linkallthelinks(ourdomainname);​

Missing quotes here:

if(href.indexOf(read_today) != -1) 

Should be:

if(href.indexOf('read_today') != -1) 

Also change:

link.setAttribute('onclick', 'alert("Okay")');

To:

link.setAttribute('onclick', function(){ alert("Okay") });

Missing quotes here:

if(href.indexOf(read_today) != -1) 

Should be:

if(href.indexOf('read_today') != -1) 

Also change:

link.setAttribute('onclick', 'alert("Okay")');

To:

link.setAttribute('onclick', function(){ alert("Okay") });

Overall, this is what you should have:

var ourdomainname = "ourdomain.com";
function linkallthelinks(domain) {
 var links = document.getElementsByTagName("a");
 for (var i = 0; i < links.length; i++) {
 var link = links[i];
 var href = link.getAttribute("href");
 if (href.indexOf('read_today') != -1) {
 link.setAttribute('onclick', function(){ alert("Okay") });
 }
 }
}
//function call
linkallthelinks(ourdomainname);​
deleted 2 characters in body
Source Link
gen_Eric
  • 227.7k
  • 42
  • 304
  • 343

Missing quotes here:

if(href.indexOf(read_today) != -1) 

Should be:

if(href.indexOf('read_today') != -1) 

Also change:

link.setAttribute('onclick', 'alert("Okay")');

To:

link.setAttribute('onclick', 'functionfunction(){ alert("Okay") }');

Missing quotes here:

if(href.indexOf(read_today) != -1) 

Should be:

if(href.indexOf('read_today') != -1) 

Also change:

link.setAttribute('onclick', 'alert("Okay")');

To:

link.setAttribute('onclick', 'function(){ alert("Okay") }');

Missing quotes here:

if(href.indexOf(read_today) != -1) 

Should be:

if(href.indexOf('read_today') != -1) 

Also change:

link.setAttribute('onclick', 'alert("Okay")');

To:

link.setAttribute('onclick', function(){ alert("Okay") });
Source Link
Sarfraz
  • 383.5k
  • 81
  • 561
  • 613
Loading
lang-js

AltStyle によって変換されたページ (->オリジナル) /