Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery load only innerHtml instead of wrapper itself

Tags:

html

jquery

ajax

Let me clarify my need, it might not be all clear from the title.

I am using:

$("#content").load("http://example.com/page1.html #content");

When I look in firebug I see #content inside #content on the page where Ajax call occurred.
So it's obvious that I need only #content's inner html to get loaded. What would be the most elegant way to achieve this with Jquery.

Thank you!

like image 351
daniel.tosaba Avatar asked Apr 21 '12 23:04

daniel.tosaba


People also ask

What is the difference between jQuery innerHTML() and innerHTML method?

The standard JavaScript innerHTML property is similar to .html () method. Both return or set HTML content. The .html () jQuery cannot be used on documents in XML format. All HTML elements have inner HTML properties. The .html () jQuery method retrieves the HTML content of the first element in the particular set of matched elements.

How to get HTML content from XML using jQuery?

The .html () jQuery cannot be used on documents in XML format. All HTML elements have inner HTML properties. The .html () jQuery method retrieves the HTML content of the first element in the particular set of matched elements. Remember: jQuery innerHTML does not exist as a function. Use .html () jQuery to set or get HTML content.

How to overwrite HTML content with jQuery?

In jQuery, innerHTML is retrieved with the following syntax of html: $(selector).html(); If you need to make jQuery .html() overwrite HTML content, use this syntax:

How to wrap an HTML structure around each element in jQuery?

Description: Wrap an HTML structure around the content of each element in the set of matched elements. An HTML snippet, selector expression, jQuery object, or DOM element specifying the structure to wrap around the content of the matched elements. A callback function which generates a structure to wrap around the content of the matched elements.


1 Answers

Use the Child Selector (http://api.jquery.com/child-selector/) on #content to select all (*) the children of #content.

$("#content").load("http://example.com/page1.html #content > *");
like image 104
Do Hoa Vinh Avatar answered Sep 29 '22 02:09

Do Hoa Vinh