The getElementById
is used to pick up elements by Ids and not by classes.
For example:
setTimeout(function() {
document.getElementById("test").disabled = true;
}, 1000);
<input id="test">
There is the getElementsByClassName
which takes elements by the set of classes, needs to have at least one, each item of the class 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 at the beginning, baz
being in the middle and bar
being at the end, because the getElementsByClassName
works by the item separated by spaces.
It is not always possible to manipulate the contents of an iframe, it affects security policies, however if iframe is of the same domain as yours then you can try to use it like this:
Suppose HTML is something like:
<iframe id="ID_DO_IFRAME"></iframe>
In javascript you can use the contentWindow
, should look 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
if it is only an item, so remove only the first 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 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;
}
}
Completion
Don’t go out using the functions randomly, learn first what they actually do, ie, Always read the documentation, this for any language, here are some links about DOM, learn how each function works before using them:
William Birth thanks for the reply, Better detail impossible. However the frame is not in the same domain as mine, so I think it will not be possible to manipulate the content... Sera has another output ?
– Paulo Fernando