abdu Posted August 19, 2018 Share Posted August 19, 2018 (edited) I tried to insert an element into iframe so first I must retrieve it by var frm = document.querySelectorAll(iframe) but cannot work. Quote ReferenceError: iframe is not defined at Object.callback... How to succeed to insertion as easily as other ordinary elements? thank so much. Edited August 19, 2018 by abdu Link to comment Share on other sites More sharing options...
Ingolme Posted August 19, 2018 Share Posted August 19, 2018 You have to pass a string, which is delimited by either single quotes or double quotes. var frm = document.querySelectorAll("iframe"); If all you're looking for is a list of iframe elements, you don't need the querySelectorAll method, getElementsByTagName will work just as well. var frm = document.getElementsByTagName("iframe"); Link to comment Share on other sites More sharing options...
abdu Posted August 19, 2018 Author Share Posted August 19, 2018 still not work; var frm = document.getElementsByTagName("iframe"); console.log('number of frame= '+ frm.length); On Chrome Devtool, Quote number of frame= 0 Link to comment Share on other sites More sharing options...
Ingolme Posted August 19, 2018 Share Posted August 19, 2018 That means that there are no iframes in your document. The might be because you're running the code before the iframes have loaded. Try putting this Javascript at the bottom of your HTML document after everything has finished loading. Link to comment Share on other sites More sharing options...
iwato Posted August 19, 2018 Share Posted August 19, 2018 Or, if you use jQuery you can wrap your code in the $(document).ready() { ... }; function. In this way, the Javascript will not be run until the full document has been loaded. Roddy Link to comment Share on other sites More sharing options...
Ingolme Posted August 19, 2018 Share Posted August 19, 2018 It's possible to do that without having to load the entire jQuery library. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now