Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
177
rated 0 times [  179] [ 2]  / answers: 1 / hits: 56170  / 9 Years ago, thu, february 19, 2015, 12:00:00

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?


More From » html

 Answers
15

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>




[#67766] Tuesday, February 17, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alfredoc

Total Points: 261
Total Questions: 128
Total Answers: 89

Location: French Polynesia
Member since Sun, Aug 2, 2020
4 Years ago
;