<script> function get_root(el) { while (el && el.parentNode) { el = el.parentNode; }; return el; } </script> <a id="MY_A_TAG" href="javascript:alert(this)" onclick="alert(get_root(document.getElementById('MY_A_TAG')))"> zeige an </a>
<style> .center { display: block; text-align: center; } .blau { background-color: #009; color: #fff; } .border { border: 1px solid #ccc; } .w100 { float: left; width: 100px; margin: 0 1px; } .clear { clear: both; } </style> <div class="center"> <a class="w100 blau border" href="#" onclick="alert('Button 1');"> Button 1 </a> <a class="w100 blau border" href="javascript:alert('href');" onclick="alert('Button 2'); return false;"> Button 2 </a> <a class="w100 blau border" href="javascript:void(0);" onclick="alert('Button 3');"> Button 3 </a> </div><br class="clear" />
<style> .button { display: inline; text-decoration: none; font-size: 80%; border-width: 3px; font-style: normal; border-style: outset; color: #fff; background-color: #99a; padding: 0px 4px; margin: 0px 4px; } a { background-color: #999;} a.button:link { background-color: #999;} a.button:visited { background-color: #999;} a.button:hover { background-color: #ccc;} a.button:active { background-color: #999;} </style> <a class="button" href="javascript:alert('Button1-Test')"> Button1 </a> <a class="button" href="javascript:alert('Button2-Test')" onmouseover = "this.style.backgroundColor='#ccc';" onmouseout = "this.style.backgroundColor='#f00';" onmousedown = "this.style.backgroundColor='#00f';" onclick = "this.style.backgroundColor='#0f0'; return false;"> Button2 </a>
<script> function get_style(that, ev, cssprop){ var doc = document, style, ev = ev || window.event; /* 1 */ if (doc.defaultView && doc.defaultView.getComputedStyle) { style = doc.defaultView.getComputedStyle(that, null); } else { //IE < 9 style = that.currentStyle || that.style; } return style[cssprop] || style.getPropertyValue(cssprop); } </script> <a href="javascript:alert('Button-Test')" onmouseover = "this.style.backgroundColor='#f00';" onmouseout = "this.style.backgroundColor='#0f0';" onmousedown = "this.style.backgroundColor='#00f';" onclick = "alert(get_style(this,event,'backgroundColor'));return true"> Button </a>
<div id="mydom"> <b>Hallo</b> <i>Welt</i> </div> <script> var win = window, doc = win.document; var s="", br = " ", child, par = doc.getElementById('mydom'); for (child = par.firstChild; child; child = child.nextSibling) { s += child.nodeName + br; } doc.write(s); </script>
<div id="myid" title="hallo welt" ></div> <script> var id = "myid", el = document.getElementById(id) || {innerHTML:''}; el.innerHTML = el.title || 'zugriffsfehler'; if (!el.nodeName) { alert(el.innerHTML); } </script>
<div id="my_id" title="nachher">vorher</div> <script> var el, id = " my_id"; try{ el = document.getElementById(id); el.innerHTML = el.title || 'zugriffsfehler'; } catch(e) { alert(e); } </script>
<img name="meineVornamen" ... /> <img name="Walter Manfed" ... /> <script> var img = window.document.images, sav = { }, name, i, erg; for (i = 0; i < img.length; i += 1 ) { name = img[i].name; if ( name && name.length > 0 ) { sav.name = i; /** 1 **/ } } erg = sav.meineVornamen + ' '; erg += sav['Walter Manfed']; alert(erg); </script>
<img name="meineVornamen" ... /> <img name="Walter Manfed" ... /> <script> var img = window.document.images, sav = { }, name, i,erg; for (i = 0; i < img.length; i += 1 ) { name = img[i].name; if ( name && name.length > 0 ) { sav[name] = i; /** 1 **/ } } erg = sav.meineVornamen; erg += ' '; erg += sav['Walter Manfed']; alert(erg); </script>