I want to insert some text in a paragraph tag, but here the paragraph tag doesn't have an ID. So, using the ID of the body tag I want to insert text. How can I do that?
Following is my HTML code:
<html>
<head xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="X-UA-Compatible" content="IE=7">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body dir="ltr" id="tinymce" class="mceContentBody " contenteditable="true">
<p><br data-mce-bogus="1"></p>
</body>
</html>
Now, I want to add text using JavaScript in the p tag.
I want that text to come from another variable. Is it possible using jQuery?
JavaScript solution:
To add text in the first p
tag.
document.getElementsByTagName("p")[0].innerHTML="Whatever text!";
Snippet:
var list = document.getElementsByTagName("p")[0].innerHTML="Whatever text!";
//alert(list);
<html>
<head xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="X-UA-Compatible" content="IE=7">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body dir="ltr" id="tinymce" class="mceContentBody " contenteditable="true">
<p>
<br data-mce-bogus="1">
</p>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With