2022-12-21 09:33:07 -05:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<body id="body">
|
|
|
|
|
|
|
|
First Name: <input name="fname" type="text" value="Michael"><br>
|
|
|
|
First Name: <input name="fname" type="text" value="Doug">
|
|
|
|
|
|
|
|
<p>Click the button to get the tag name of the first element in the body that has tag P.</p>
|
|
|
|
|
|
|
|
<button onclick="myFunction()">Try it</button>
|
|
|
|
|
|
|
|
<p id="demo"></p>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
function myFunction() {
|
2022-12-21 09:47:41 -05:00
|
|
|
var x = document.getElementById('body').getElementsByTagName("P").item(0).outerHTML;
|
2022-12-21 09:33:07 -05:00
|
|
|
window.alert(x);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|