tns12
tns12

Reputation: 33

GetElementById giving ReferenceError in Chrome

I have no idea what's going on because I have never had problems with JS but here we go. I keep getting an Uncaught ReferenceError in Chrome with this code:

function showShareButtons() {
    var buttons = getElementById("sharebtns");
    document.buttons.style.visibility = 'visible';
}

Can someone tell me what's wrong? Thanks!

Upvotes: 1

Views: 65

Answers (3)

Anonymous
Anonymous

Reputation: 12017

You can't simply declare getElementById by itself for a variable. You would need to use document.getElementById:

function showShareButtons() {
    var buttons = document.getElementById("sharebtns");
    buttons.style.visibility = 'visible';
}

Even though you eventually use document in your code, it would not be the same since the variable is unable to be declared as anything definitive.

Upvotes: 1

shpyo
shpyo

Reputation: 221

It should be like: function showShareButtons() { var buttons = document.getElementById("sharebtns"); buttons.style.visibility = 'visible'; }

Upvotes: 1

Joakim M
Joakim M

Reputation: 1803

document.getElementById("sharebtns");

Upvotes: 1

Related Questions