How to create element in background script?

I'm doing this in background script:

var link = document.createElement('div');

Then link is null. I guess it's because extensions background page have no DOM, or am i have no access to it? Anyway i'm need this to make copy to clipboard. Here part where i'm try to use it:

function selectionOnClick(info, tab) {
    var link = document.createElement('div');
    var range = document.createRange();

    link.innerHTML = ShortURL(info.selectionText);
    range.selectNode(link);

    window.getSelection().addRange(range);

    try {
        var successful = document.execCommand('copy');
        if (!successful) {
            alert("Your browser doesn't support copy to clipboard.");
        }
    } catch(err) {
        alert("Your browser doesn't support copy to clipboard.");
    }

    window.getSelection().removeAllRanges();
    link.parentNode.removeChild(link);
}

chrome.contextMenus.create({'title': 'Short selected', 'contexts':['selection'], 'onclick':selectionOnClick});


ANSWERS:


You have created the node but have not append it to anything. Append it to body:

document.getElementsByTagName('body').appendChild(link);  

just make the "link" variable global then initialize it inside the function..

var link = null;

function selectionOnClick(info, tab) {
    link = document.createElement('div');
.
.
.


 MORE:


 ? Intercepting all API calls with browser addon
 ? How to trigger an event only when the user changes the URL?
 ? Chrome Extension Settings page
 ? Need div arrangement as shown in the screenshot
 ? Dynamically append SVG sprite in chrome extension
 ? How to tell if a tab is website or just an image?
 ? How to stop Adsense loading mixed content on https site?
 ? Unity + PHP + SSL + Https + hackers
 ? Artifactory - Migrate from HTTP to HTTPS
 ? Selenium and Chrome error: --ignore-certificate-errors