2

I will try to expand my problem:

I have a link:

<a href="#" onClick="Display(); return false;">Display</a>

I have some styles:

<style type="text/css">
p {
 background-color: #AFA99B;
}
</style>

And the folowing js code:

function printf(MyHtml){
document.write(MyHtml); 
}

function Display(){
printf("<p>some html code<p>");
//...
}

So when the user click the link, I must add some html content to the body & the new added elements must use the styles defined. That's all.

Hidalgo
  • 765
  • 1
  • 9
  • 28

1 Answers1

2

That's the problem was talking about in my comment. You are calling document.write(MyHtml) after the document was fully loaded.

It will completely replace the document (see the documentation). Inspect it, you will see that there is an empty head (also see this and this example).

Use other methods to manipulate the DOM.

Community
  • 1
  • 1
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143