0

I have, for example, the following <object> in my page:

<object id="obj1" data="URL"></object>

Is there any way to get the html object in jquery?

0

2 Answers 2

4

As with any element with an id: jQuery('#obj1')

Or to get all object elements: jQuery('object')

Sign up to request clarification or add additional context in comments.

3 Comments

@StefanoGuarella — You have no content between the <object> start tag and the </object> end tag, so of course getting an HTML representation of the child nodes of the element will give you a blank result.
@StefanoGuarella You should put the code within document ready handler.
Are you asking how to read the content of HTML document loaded into an object? Why aren't you using an iframe, which has standard interfaces for that sort of thing?
3

"jQuery get html"

It seems like you're asking how to get the HTML rendering of the element.

If so, do this:

var markup = $("#obj1")[0].outerHTML;

Or using .prop():

var markup = $("#obj1").prop("outerHTML");

Or without jQuery:

var markup = document.getElementById("obj1").outerHTML;

3 Comments

TypeError: document.getElementById("obj1") is null TypeError: $("#obj1")[0] is undefined
@StefanoGuarella: Naturally you can't select an element until it is available. If your script is placed on the page before the <object>, then it won't find it. Put your code after the element, or run it inside a handler passed to $(document).ready().
@StefanoGuarella: Please just update your question to show what you're doing, and please describe in detail exactly what your goal is.

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.