Forum Moderators: open
<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?
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 ;-)