I tried this the intuitive way with both JavaScript and jQuery, with no dice for either.
document.GetElementsByT开发者_运维技巧agName('iframe');
got me:
Uncaught TypeError: Object # has no method 'GetElementsByTagName'
and $('iframe')
got me undefined
.
Is an iframe an element? Is there a way to do this?
I'm trying to return all the page iframes.
Thank you.
The function needs a lower case g like so document.getElementsByTagName('iframe')
. Yes, iframe is a tag. https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByTagName
An iframe
is just a normal element.
You need to observe the correct case of getElementsByTagName()
(lowercase leading g
, the DOM API uses camelCase, not PascalCase).
Also, for jQuery, $('iframe')
should work.
Try this:
function getFramesWithNoId() {
var result = [];
var frames = document.getElementsByTagName('iframe');
for (var i = 0; i < frames.length; i++) {
if (!frames[i].id) {
result.push(frames[i]);
}
}
return(result);
}
You can see in action here: http://jsfiddle.net/jfriend00/Uxsyg/
精彩评论