How to get css and the html into JS function?

how do I get the css and the html into the function?

<html>
<head>
<script type="text/javascript">
function myFunction()
{
return ("Hello world!");
}
</script>
</head>
<body>
<div style="float:right;">
<script type="text/javascript">
document.write(myFunction())
</script>
</div>
</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>

Thanks. I understand that. Your use of getAttribute lets me ask this question.

Now, can you work createElement into your script?

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

Thanks, but what about the css? Isn’t there an advantage to getting both into the javascript?

Hy,
Try test and understand this code:

<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>

U can do like:

<html>
<head>
<script>
function m()
{
y=document.getElementById(“linhpro”);
alert(y.innerHTML);
}
</script>
</head>
<body onload=m()>
<h1 id=“linhpro”>Hello word</h1>
</body>
</html>