Ajax load div, part of CSS not working

I use ajax to load the contents of the div, but the content of the div does not take the CSS of the page.

Example: - This link will be loaded into

<a href="#" onclick="javascript:loadAjax('test.html')">Test</a> 

<div id="result">
<table class="tablesorter">
<thead>
    <tr>
        <th>Header 1</th><th>Header 2</th>
    </tr>
</thead>
<tbody>

    <tr><td>Record 1</td><td>Desc 1</td></tr>
</tbody>    
</table>
</div>

In my CSS:

table.tablesorter thead tr th, table.tablesorter tfoot tr th {
    background-color: #e6EEEE;
    border: 1px solid #FFF;
    font-size: 8pt;
    padding: 4px;
}

table.tablesorter thead tr .header {
    background-image: url(bg.gif);
    background-repeat: no-repeat;
    background-position: center right;
    cursor: pointer;
}

In my test.html, this is the same table with a different entry:

<table class="tablesorter">
    <thead>
        <tr>
            <th>Header 1</th><th>Header 2</th>
        </tr>
    </thead>
    <tbody>

        <tr><td>Record 2</td><td>Desc 2</td></tr>
    </tbody>    
    </table>

The problem I am facing is that before "test.html" loads, CSS is fine. But after clicking the link that suggests loading test.html, the CSS background still shows that the “cursor: pointer” and “background image” no longer work.

What should I do to make it work? Thanks in advance!

Added to loadAjax code:

   var http_request = false;
   function loadAjax(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url + parameters, true);
      http_request.send(null);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
     // alert(http_request.status);
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('result').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
+5
source share
1 answer

css test.html. iframe , CSS . .

. , , . test.html , CSS, .

<table class="tablesorter">
    <thead>
        <tr>
            <th>Header 1</th><th>Header 2</th>
        </tr>
    </thead>
    <tbody>

        <tr><td class="header">Record 2</td><td>Desc 2</td></tr>
    </tbody>    
    </table>
+3

All Articles