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

Return to Question

deleted 33 characters in body
Source Link
Didier Ghys
  • 30.6k
  • 9
  • 77
  • 82

I have some code that I'm working on for my work. We're trying to loop through all the links on our page and automatically add an onclick event. However, the loop doesn't appear to be "looping" at all. Could somebody please help?

var ourdomainname = "ourdomain.com";
function linkallthelinks(domain) {
 var links = document.getElementsByTagName("a");
 for (i = 0; for(i=0;i i<links< 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);
 ;​

I have some code that I'm working on for my work. We're trying to loop through all the links on our page and automatically add an onclick event. However, the loop doesn't appear to be "looping" at all. Could somebody please help?

var ourdomainname = "ourdomain.com";
function linkallthelinks(domain) {
 var links = document.getElementsByTagName("a");
 for(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);
 

I have some code that I'm working on for my work. We're trying to loop through all the links on our page and automatically add an onclick event. However, the loop doesn't appear to be "looping" at all. Could somebody please help?

var ourdomainname = "ourdomain.com";
function linkallthelinks(domain) {
 var links = document.getElementsByTagName("a");
 for (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);​
Source Link
ccarnley7
  • 441
  • 4
  • 10
  • 20

Javascript for loop not looping

I have some code that I'm working on for my work. We're trying to loop through all the links on our page and automatically add an onclick event. However, the loop doesn't appear to be "looping" at all. Could somebody please help?

var ourdomainname = "ourdomain.com";
 function linkallthelinks(domain)
 {
 var links = document.getElementsByTagName("a");
 for(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);
 
lang-js

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