If you're looking to create those attention-grabbing "alerts" that are commonly found at the top of websites nowadays (similar to stackoverflow), one method I typically use is by inserting a div
with the id of message
right after the opening body tag.
If directly modifying the HTML isn't an option, you can achieve the same effect using JavaScript to add div#message
as the initial div in the Document Object Model (DOM). This will ensure that all other elements are automatically pushed down to accommodate the new div's position.
For cases involving absolute positioned elements, it's advisable to enclose all page content within a div wrapper that has its position set to relative. By doing so, when the wrapper shifts downward, all content inside it will adjust accordingly. If altering the HTML directly is not feasible, there likely exists a suitable wrapper already present in your HTML; you can utilize CSS to change its position property.
In jQuery, you can simply employ the prepend function to insert a div as the first child of body
.
$('body').prepend("<div id='message'></div>");
Alternatively, in pure JavaScript, a snippet like the following (may require testing) can be used:
var myDiv = document.createElement('div');
myDiv.setAttribute("id","message");
insertBefore(myDiv,document.body.firstChild);