Rabu, 01 Juli 2009

Apa Perbedaan dari getElementByID, getElementByName dan getElementByTagName ?

getElementByID : mengambil elemen berdasarkan id, c/:
<html>
<body>
<p id='tes'> Hallo bang topan <script language = 'Javascript'>
txt = document.getElementByID('tes').innerHTML;
document.write(txt);
</script>
</body>
</html>

getElementByName : mengambil elemen berdasarkan nama, c/:
<html>
<body>
<p name='tes'> Hallo bang topan </p>
<script language = 'Javascript'>
txt = document.getElementByName('tes').innerHTML;
document.write(txt);
</script>
</body>
</html>

getElementByTagName
<html>
<body>
<p> Hallo bang topan </p>
<script language = 'Javascript'>
txt = document.getElementByTagName('p').innerHTML ;
document.write(txt);
</script>
</body>
</html>

semuanya menghasilkan output yang sama

Tidak ada komentar: