I loaded a html page into div in a main page with jquery but the properties on the html page didnt transfer to the main one. for example in the body - color. Anyone know how to do it? Thabk you!
Asked
Active
Viewed 143 times
-2
-
possible duplicate - http://stackoverflow.com/questions/14735762/load-html-page-dynamically-into-div-with-jquery – Ivan Nov 24 '14 at 13:22
1 Answers
2
.load
only pulls the HTML - not CSS, JS, etc. I suggest you import the styles and scripts, or -- less preferably -- use an <iframe>
.

Mooseman
- 18,763
- 14
- 70
- 93
-
Its not possible to import css, css loads when page loads and you are doing ajax call which is .load() and you dont refresh page, so css can't be applied to that loaded content. Everything you can do is to create callback function and then give you elements css with jquery .css() function – Strahinja Djurić Nov 24 '14 at 13:30
-
@StrahinjaRadjuDjurić statement that it is not possible is incorrect, there are several ways to do it – charlietfl Nov 24 '14 at 13:32
-
@StrahinjaRadjuDjurić Not entirely true. You can use JS to get CSS files from the loaded page, then load them on the current page. However, this is very dangerous: the new CSS file can override your own styles. If you're looking to get styles from the page, use an `iframe`. If you can include relevant styles in your own page, do so. – Mooseman Nov 24 '14 at 13:33
-
@charlietfl I believe so, i just didn't said it in right way :) – Strahinja Djurić Nov 24 '14 at 13:38