admin管理员组

文章数量:1419220

I am trying to use .load so I can load an external page into a div on the current user's page. When I call .load , does it load the content and then style it with the current stylesheet defined in that page? If not how would I go about doing that? Example;

<head>
  <link ref="stylesheet" href="main.css"/>
</head>
<body>
  <div class="section">
    <h2>Say this div was loaded with .load after page loaded</h2>
  </div>
</body>

If .section was loaded via .load, would the style be loaded of the current page and modify that div after it loaded or is it just the html that got loaded with no styling. If it is the latter, how would I style it without using <style> tags?

I am trying to use .load so I can load an external page into a div on the current user's page. When I call .load , does it load the content and then style it with the current stylesheet defined in that page? If not how would I go about doing that? Example;

<head>
  <link ref="stylesheet" href="main.css"/>
</head>
<body>
  <div class="section">
    <h2>Say this div was loaded with .load after page loaded</h2>
  </div>
</body>

If .section was loaded via .load, would the style be loaded of the current page and modify that div after it loaded or is it just the html that got loaded with no styling. If it is the latter, how would I style it without using <style> tags?

Share Improve this question edited Jan 23, 2012 at 4:25 Sameera Thilakasiri 9,50810 gold badges53 silver badges87 bronze badges asked Jan 23, 2012 at 4:14 Joe TorracaJoe Torraca 2,0185 gold badges32 silver badges50 bronze badges 1
  • 1 Did you try it and see what happens? You could answer your own questions that way. – Brian Glaz Commented Jan 23, 2012 at 4:20
Add a ment  | 

4 Answers 4

Reset to default 2

Anytime you alter the DOM in a way that causes a redraw (such as adding visible elements to the DOM), each element is checked against all the rules in the CSS style-sheets.

So to answer your question directly. Yes, the styles will be added to elements that are added to the DOM at anytime.

If the css is available on the page which contains section div then the styles will be applied after load renders the content. Also if the styles are part of the load response then also it will be rendered with styles applied.

If the styles are not available on the page and also you are not getting it in the load response then you have to explicitly get it using ajax or adding a link tag with appropriate stylesheet url into the page.

Your style of the current page will apply to the content loaded via .load

You can specify CSS in your main .css file, so when DOM is added, styles are taken from the main CSS file.

本文标签: javascriptJQuery load page into div with stylesStack Overflow