Question: Criteria - I prefer not to use any additional library, want to perform this with just pure javascript, but happy to use one if needed.

I want to add an additional class to anchor elements which have a query string of 'xyz=negate'. My page typically has more than 200 anchor elements. I am looking for the most efficient way to achieve this. 

The user base for my website still has a decent number of IE 8 (intranet site) and hence looking for the most efficient code. My page has anchor elements which look like the following

```
<a href="http://www.w3schools.com?id=43&xyz=negate">Visit W3Schools.com!</a>
<a href="http://www.w3schools.com?id=47&xyz=nonnegate">Visit W3Schools.com!</a>
<a href="http://www.w3schools.com?id=3&xy=negate">Visit W3Schools.com!</a>
<a href="http://www.w3schools.com?id=42&xyz=negate&yz=external">Visit W3Schools.com!</a>
<a href="http://www.w3schools.com?id=43&xyz=negate">Visit W3Schools.com!</a>

```

I want to add class to the first, fourth and fifth anchor element in the above example.

Answer: 
Having the extra headers will have turned all of your data into factors (or character if you used `stringsAsFactors=FALSE`):

```
dd <- read.table(text="var1    var2    var3    var4
   1       1       1     'ch'
   1       1       1     'ch'
   1       1       1     'ch'
var1    var2    var3    var4
   1       1       1     'ch'
   1       1       1     'ch'
   1       1       1     'ch'
var1    var2    var3    var4")

```

Convert all but last column to numeric (ignore warnings):

```
dd[,1:3] <- lapply(dd[,1:3],
                    function(x) as.numeric(as.character(x)))

```

Throw away rows where the first three columns are `NA`:

```
dd <- dd[apply(dd[,1:3],1,function(x)!all(is.na(x))),]

```
How about this:

```
rpts <- unique(as.vector(sapply(1:ncol(d), function(i) which(names(d)[i]==d[,i]))))
d <- d[-1*rpts,]

```

The first line extracts those rows in which the respective column name is appeared for all columns (i.e. `names(d)`). Second line accounts for deleting those extracted rows (i.e. `rpts`).

**data**

```
d <- structure(list(var1 = structure(c(1L, 1L, 1L, 2L, 1L, 1L, 1L, 
2L), .Label = c("1", "var1"), class = "factor"), var2 = structure(c(1L, 
1L, 1L, 2L, 1L, 1L, 1L, 2L), .Label = c("1", "var2"), class = "factor"), 
    var3 = structure(c(1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L), .Label = c("1", 
    "var3"), class = "factor"), var4 = structure(c(1L, 1L, 1L, 
    2L, 1L, 1L, 1L, 2L), .Label = c("ch", "var4"), class = "factor")), .Names = c("var1", 
"var2", "var3", "var4"), class = "data.frame", row.names = c(NA, 
-8L))

```