Welcome to WebmasterWorld Guest from 207.241.229.227
Forum Moderators: open
I am new to JS and this is just a sandbox page.
Any ideas?
<html>
<head>
<title>DOM Scripting Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link id="stylelink" rel="stylesheet" type="text/css" href="jstest.css" media="screen" />
<script type="text/javascript">
function insertdiv(){
var newdiv = document.createElement('div');
var newpara = document.createElement('p');
var thetext = document.createTextNode('test');
newpara.appendChild(thetext);
newdiv.appendChild(newpara);
newdiv.setAttribute("className","floater")
document.getElementById('jstest').appendChild(newdiv);
}
</script>
</head>
<body id="jstest">
<a href="javascript:insertdiv()">click to insert div</a>
</body>
</html>
[color=brown]elm.setAttribute('class','whatever')[/color]
The reason we can't use
[color=brown]elm.[red]class[/red] = 'whatever'[/color]
is that class is a JS reserved word. This doesn't apply to setAttribute, because it doesn't use dot syntax (language neutral). IE has forgotten that. So that's one reason to stick with dot syntax (apart from the fact that it's shorter). Strict whatever can wait.
- after all, nobody worries about accessing nodelist members using
[blue][n][/blue]
rather than [blue].item(n)[/blue]