0

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>
1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by niche1
0

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>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.