-3

Whenever i tried using document.write it replaces the current html page content in example i have this HTML

 <body>
<div>
     <h1>Hello</h1>
</div>

and this jQuery

var notif = document.write("<div class = 'bg' style = 'height:250px; width:400px; z-index:10; background:red;'>Good Morning!</div>");
 $('body').append(notif).delay(5000).fadeOut()

this replace the whole page big Hello will be gone the jQuery will work after a 5 seconds it disappears then displays nothing?

Aze Ronquillo
  • 47
  • 1
  • 7

1 Answers1

0

document.write is not needed for 'append' (document.write writes the content to the page replacing the existing content fully). Pls see the documentation for jquery append: http://api.jquery.com/append/

You'll have to just write

var notif = "<div class = 'bg' style = 'height:250px; width:400px; z-
index:10; background:red;'>Good Morning!</div>";
$('body').append(notif).delay(5000).fadeOut()