How can I insert a line to the top of the <body>?

Discussion in 'JavaScript' started by Betty_S, Feb 28, 2007.

  1. #1
    I have an interesting question:

    Can I insert this <h1><a href=”blablabla”> blablabla </a></h1> directly on the begging/top/first line of the <body>,

    Is that possible via JS?

    Thanks.
     
    Betty_S, Feb 28, 2007 IP
  2. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not sure why you'd want to use javascript for this, but

    
    <html>
    	<body>
    		text that's here already.
    		<script type="text/javascript">	
    			var body = document.getElementsByTagName("body")[0];
    			body.innerHTML = "<h1><a href=”blablabla”> blablabla </a></h1>" + body.innerHTML;
    		</script>
    	</body>
    </html>
    
    Code (markup):
     
    giraph, Feb 28, 2007 IP