James Patrick
James Patrick

Reputation: 189

Targetting div by ID with chrome.tabs.executeScript

I'm trying to use chrome.tabs.executeScript to target a specific div on my page.

function click(e) {
  chrome.tabs.executeScript(null,
      {code:"document.body.div#wrap.style.color='" + e.target.id + "'"});
  window.close();
}

Consule is telling me: Uncaught SyntaxError: Unexpected token ILLEGAL


Is this a syntax problem, or is this not possible?

Upvotes: 0

Views: 276

Answers (1)

Rob W
Rob W

Reputation: 349142

Use document.querySelector instead of the syntactically invalid div#wrap:

chrome.tabs.executeScript(null, {
    code: "document.querySelector('div#wrap').style.color='" + e.target.id + "';"
});

Upvotes: 2

Related Questions