Can someone work createElement into this script to demo its use?

I think the two can work together, but I don't know how.

<html>
<head>
<script type="text/javascript">
function myFunction(anid)
{
  var cssatr = document.getElementById(anid).getAttribute('style');   // get the value of "style"
  var htmlanid = document.getElementById(anid).innerHTML;        // get html code
  return ('css style = '+ cssatr+ '<br>html = '+ htmlanid);
}
</script>
</head>
<body>
<div id="anid" style="float:right;">
Some html code
</div>
<script type="text/javascript">
document.write(myFunction('anid'))
</script>
</body>
</html>

How close is this to display a div ? Admittedly, I'm guessing at the use of createElement() and setAttribute().

<html>
  <head>
    <script type="text/javascript">
        var div = document.createElement('div');
        div.style.display = 'absolute';
        div.style.left = '500px';
        div.style.top = '200px';
        div.style.width = '100px';
        div.style.height = '100px';
        div.style.backgroundColor = 'red';
        div.setAttribute('id', 'link-container');
    </script>
  </head>
<body>
  <div id="link-container"> 
  <script type="text/javascript">
     document.write(div);
  </script>
  </div>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.