11

How come I cannot make $(frame) a jQuery object in the below case? Below is my output from chrome developer tools.

console: mainFrame
output: <frame src=​"http:​/​/someurl.com" name=​"mainFrame">​
console: $(mainFrame).contents()
output: SyntaxError: Failed to execute 'querySelector' on 'Document': '[object HTMLFrameElement]' is not a valid selector.

Edit:

to respond to comments...

$.toString()
"function $(selector, [startNode]) { [Command Line API] }"

typeof(mainFrame)
"object"

jQuery
ReferenceError: jQuery is not defined
6
  • 4
    Could you provide relevant code instead of console output?! Commented Mar 19, 2014 at 11:57
  • 2
    What is the output of $.toString() and typeof mainFrame? Commented Mar 19, 2014 at 11:58
  • 1
    I think the problem is that this is a frame tag and if you're not on the same domain then it is a security violation. If you are you might still need to add some context like the following: $('#myselector',top.frames["mainFrame"].document).contents(); Commented Mar 19, 2014 at 12:10
  • I don't think $ is jQuery here, try jQuery(mainFrame).contents() Commented Mar 19, 2014 at 12:26
  • It looks like jQuery doesn't support frame elements: forum.jquery.com/topic/… Commented Mar 19, 2014 at 12:39

3 Answers 3

16

jQuery doesn't seem to be included in your document. Some browsers set $ to querySelector by default (which is a native way to select elements of the DOM using css-like syntax), thereby your error message. Try adding

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

This was the answer. Thank you!
1

Looks like jQuery is not included into the DOM, try to include jQuery either by CDN or add standalone jQuery into the DOM.

You can confirm the jQuery installation by typing $ into the browser inspect tab. If the output is something like

> $
ƒ (e,t){return new x.fn.init(e,t,r)}

then jQuery added successfully.

Comments

0

Try

$(frame).contents();

Or

$("html", frame);

not sure which one will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.