Get Paragraph Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Paragraph

Introduction

The Paragraph object represents an HTML <p> element.

You can access a <p> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP">I am a paragraph. </p>

<button onclick="myFunction()">get id of paragraph element</button>

<p id="demo"></p>

<script>
function myFunction() {//from w w w  .ja  v  a  2  s  .co  m
    var x = document.getElementById("myP").id;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials