JQuery loading page in a div with styles

I am trying to use .load , so I can load the external page into a div on the current user page. When I call .load , does the content load and then style it with the current stylesheet defined on this page? If not, how would I do it? 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 , will the style load the current page and modify this div after loading it or is it just html that loaded without styling. If this is the last, how would I style it without using the <style> tags?

+4
source share
4 answers

Anytime you change the DOM in a way that causes a redraw (for example, adding visible elements to the DOM), each element is checked with all the rules in CSS styles.

So, to answer your question directly. Yes, styles will be added to elements added to the DOM at any time.

+2
source

If css is available on the page containing the section div, styles will be applied after load displays the content. Also, if styles are part of the load response, then it will also be displayed with styles.

If styles are not available on the page, and you don’t get it in response to the download, you must explicitly get it using ajax or add a link tag with the corresponding URL to the stylesheet on the page.

+1
source

Your current page style will apply to content uploaded via .load

+1
source

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

+1
source

Source: https://habr.com/ru/post/1392407/


All Articles