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:
Posting Komentar