javascript - JQuery load page into div with styles - Stack Overflow

I am trying to use .load so I can load an external page into a div on the current user's page. Whe

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745298857a4621310.html

相关推荐

  • javascript - JQuery load page into div with styles - Stack Overflow

    I am trying to use .load so I can load an external page into a div on the current user's page. Whe

    8小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信