I want to use javascript to set attribute for selected element on webpage.

I have found 2 ways to set attribute using javascript

1

```
   WebDriver driver; // Assigned elsewhere
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("document.getElementByID('//id of element').setAttribute('attr', '10')");

```

2

```
WebElement element = driver.findElement(By.id("foo"));
    String contents = (String)((JavascriptExecutor)driver).executeScript("return arguments[0].innerHTML;", element);

```

But I want to apply javascript to specific webelement which i have found using selenium webdriver

as an example i have select one link using selenium webdriver

```
driver.findElement(By.linkText("Click ME"))

```

Now I want to set attribute of this webelement using javascript 

but I don't know how to combine both

please help me to find solution