getElementById
is used to get elements by IDs, not classes.
For example:
setTimeout(function() {
document.getElementById("test").disabled = true;
}, 1000);
<input id="test">
There is getElementsByClassName
that takes elements by the set of classes, must have at least each class item is divided by a space, for example:
console.log(document.getElementsByClassName("foo").length);
console.log(document.getElementsByClassName("baz").length);
console.log(document.getElementsByClassName("bar").length);
<input class="foo baz bar">
See that all return 1 in .length, even foo
being in the beginning, baz
being in the middle and bar
being in the end, because getElementsByClassName
works by the item separated by spaces.
It is not always possible to manipulate the contents of an iframe, this affects security policies, however if the iframe is from the same domain as yours then you can try to use it like this:
Assuming HTML is something like:
<iframe id="ID_DO_IFRAME"></iframe>
In javascript you can use contentWindow
, you should stay something like (this way it will remove all items that have this class):
function setDisabled() {
var iframe = document.getElementById("ID_DO_IFRAME").contentWindow;
var shareBtns = iframe.document.getElementsByClassName("glyphicon-share-twitter");
for (var i = shareBtns.length - 1; i >= 0; i--) {
shareBtns[i].disabled = true;
}
}
or with querySelector
is just an item, so remove only the first one found:
function setDisabled() {
var iframe = document.getElementById("ID_DO_IFRAME").contentWindow;
iframe.document.querySelector("glyphicon-share-twitter").disabled = true;
}
}
If the element is not within the IFRAME, then simply do this:
function setDisabled() {
var shareBtns = document.getElementsByClassName("glyphicon-share-twitter");
for (var i = shareBtns.length - 1; i >= 0; i--) {
shareBtns[i].disabled = true;
}
}
Conclusion
Do not go out using the functions randomly, first learn what they really do, ie ALWAYS read the documentation , this for any language, here are some links about DOM, learn how each function works before using them: