views:

48

answers:

2

For example:

<div id="d">ss</d>

How can I get the div by id?

A: 

document.getElementById('id');

lunixbochs
not success.the code "document.getElementById('id');" in in background.html. so can not get the div.I want click the extensison button that can do somethine with current page
Gio
You mean document.getElementById('d'); ?
Ernelli
OP changed the question ;)
lunixbochs
+1  A: 

You should access the web page using the contentWindow variable when writing a Chrome Extension.

contentWindow.document.getElementById("d");
Sohnee
background.html"<html><head><script>chrome.browserAction.onClicked.addListener( function(tab){ alert(contentWindow.getElementById('gc-topnav')); } );</script></head><body></body></html>"how can I access the web page using the contentWindow variable?TKs~
Gio