0

The problem I am encountering is that when I use javascript to get the html file inside another html file, the background image turns invisible. But when I open the file with the background image the image is visible.

To make this understandable, I want to include second.html (with background image) in first.html using javascript without the image being invisible.

First.html (main)

<html>
    <head>
        <script> 
            $(function(){
                $("#second").load("second.html");
            });
        </script> 
    </head>
    <body>
        <div id="second"></div>
    </body>
</html>

Second.html (with image)

<body style="background-image: url('img/dashboard-layout.png'); background-repeat: no-repeat; background-color: #303032;">
    <!--Code goes here-->
</body>
3dgoo
  • 15,716
  • 6
  • 46
  • 58
Dler Hasan
  • 233
  • 1
  • 11

1 Answers1

0

This is my working example first.html

<html>
  <head>
    <script> 
       $(function(){
            $("#second").load("second.html");
        });
    </script> 
   </head>
   <body>
      <div id="second" style="height:100px;width:100%;"></div>
   </body>

second.html

<div style="height:100px;width:100%;background-image: url('http://blogs.atlassian.com/wp-content/uploads/01-new-icons.png'); background-color: #303032;">

Note that div has default height = 0px you need to set height for divs to work this eg.

Guru
  • 1,303
  • 18
  • 32