user3678835
user3678835

Reputation:

Google chrome extension returns undefined for any getElement

So I tried writing a pointless chrome extension, but in my content script any of the getElements return undefined.

Here is my manifest.json

    {
"name": "xyx",
"version": "1.0",
"manifest_version": 2,
"description": "xyx",
"permissions":[
    "tabs",
    "bookmarks",
    "activeTab"
],
"content_scripts":[
 {
    "matches":["http://*/*"],
    "js":["func.js"],
    "run_at":"document_end",
    "all_frames":true
 }
]

}

and here is my content script

    var x = document.getElementsByTagName["href"];
    for(var i = 0; i <= x.length; i++){ 
        x[i].innerHTML = "http://www.facebook.com";
    }

For some reason I cant get it to stop returning undefined.Any solution's?

Upvotes: 0

Views: 451

Answers (1)

user1908391
user1908391

Reputation:

href is not a tag, but an attribute. Another issue with the above code is that you should use round brackets (), as var x = document.getElementsByTagName("a");

Upvotes: 1

Related Questions