Forum Moderators: open

Message Too Old, No Replies

div in innerHTML

         

treeleaf20

1:14 pm on Aug 6, 2004 (gmt 0)

10+ Year Member



I was wondering if you could call a <div> tag that is in innerHTML. An example would be something like this:

<script language="JavaScript" type="text/JavaScript">
function innerhtml(){

url = 'http:\/\/www.test.com/general/includes/style_ge.css';
document.getElementById('styles').href=url;

document.getElementById("results").innerHTML = "<div id='styles'></div>";
}

</script>

It doesnt work that way so does anyone know of a way that I get this to work with the <div> tag inside of the innerHTML?

BjarneDM

9:17 pm on Aug 9, 2004 (gmt 0)

10+ Year Member



what are you trying to do?

you first statement -

document.getElementById('styles').href=url
- has to be referencing an <a>-tag, so you are modifying the href-attribute of the tag (<a>-tags are the (almost) only tags with a href-attribute)

next, you are modifying the innerHMTL of the <a>-tag, so you end up with the following :

<a id="styles" href="{your url}"><div id='styles'></div></a>

this is bad coding for at least the following reason: you have now got two id-attributes with the same value, which isn't allowed as id-attributes are supposed to be unique.

and I'm also suspecting that this isn't at all what you were expecting nor attempting ;-)