Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we have content text directly in <div>?

Tags:

xhtml

can we have content text directly in <div>text content</div> or it should be like <div><p>text content</p></div>? according to web standards.

like image 928
Jitendra Vyas Avatar asked Nov 02 '09 10:11

Jitendra Vyas


People also ask

How do I put text inside a div?

Use the textContent property to get the text of a div element, e.g. const result = element. textContent . The textContent property will return the text content of the div and its descendants. If the element is empty, an empty string is returned.

How do I display the content of a div?

First, we will create a basic HTML code for the div elements and apply different CSS styling to make it display inline. CSS properties: In this article, we will use below CSS properties. Display: We will use display: flex and display: inline-block property to show div elements inline.

How do I add content to a div in HTML?

$("#divID"). html("this text will be added to div"); Use . html() without any arguments to see that you have entered.


2 Answers

You can have character data directly inside a div element. If (and only if) that character data is a paragraph, then it should also be marked up as a paragraph (as per your second example). If you only have one paragraph of content inside the div, then you should usually avoid having the div element as it serves no purpose.

like image 160
Quentin Avatar answered Oct 26 '22 02:10

Quentin


You can have it directly in a div. The div is often used to group block-elements to format them with styles, but normal, unmarkedup text in a div is just fine.

like image 33
karim79 Avatar answered Oct 26 '22 03:10

karim79



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!