
Originally Posted by
SawnDiddle
<script language="JavaScript">
The language attribute was deprecated long ago:
HTML Code:
<script type="text/javascript">
function change(id, newClass) {
identity=document.getElementById(id);
identity.className=newClass;
}
As you have omitted the var keyword, the identity variable will become global (not a desirable thing). Feature detection and a bit of defensive programming wouldn't go amiss, either:
Code:
function setClassName(id, className) {
var element;
if(document.getElementById && (element = document.getElementById(id))) {
element.className = className;
}
}
<a href="javascript
:;" [...]
Ack!
I hope that this is just an example. Don't use the javascript: pseudo-scheme like this; it's not what it was designed to do, and can have negative effects. Using an empty fragment identifier and cancelling the click event is marginally better (but only just):
HTML Code:
<a href="#" onclick="setClassName('changeme', 'second'); return false;">
Mike
Bookmarks