Jquery html()方法如果我们在p标签中放置一个div,它将不起作用?

时间:2022-11-03 10:07:12

This is my HTML:

这是我的HTML:

  <div class="accor">
  </div>
  <div class="accordionContentTwoCol">
   <p class="noEdit">
     <div>   name : </div>
  </p>
 <div>

I need to find html content of accordionContentTwoCol div (i have access only to accor).
If i try to print html inside accordionContentTwoCol div like this:

我需要找到accordionContentTwoCol div的html内容(我只能访问accor)。如果我尝试在accordionContentTwoCol div中打印html,像这样:

alert("html inside accordionContentTwoCol :"+$('.accor').next().html());

It gives output like this:
Jquery html()方法如果我们在p标签中放置一个div,它将不起作用?

输出是这样的:

Though HTML inside accordionContentTwoCol is:

虽然HTML内部的accordioncontenttwcol是:

<p class="noEdit">
         <div>   name : </div>
</p>

why that happens?

为什么出现这种情况呢?

4 个解决方案

#1


5  

An authoritative place to look for allowed containment relations is the HTML spec. See, for example, http://www.w3.org/TR/html4/sgml/dtd.html. It specifies which elements are block elements and which are inline. For those lists, search for the section marked "HTML content models".

查看允许的包容关系的一个权威的地方是HTML规范。它指定哪些元素是块元素,哪些是内联的。对于这些列表,搜索标有“HTML内容模型”的部分。

For the P element, it specifies the following, which indicates that P elements are only allowed to contain inline elements.

对于P元素,它指定以下内容,这表明P元素只允许包含内联元素。

<!ELEMENT P - O (%inline;)*            -- paragraph -->

This is consistent with http://www.w3.org/TR/html401/struct/text.html#h-9.3.1, which says that the P element "cannot contain block-level elements (including P itself)."

这与http://www.w3.org/TR/html401/struct/text.html#h-9.3.1是一致的,它说P元素“不能包含块级元素(包括P本身)”。

Why <p> tag can't contain <div> tag inside it?

为什么

标签不能包含

标签?

#2


1  

The markup you use is wrong. The <div> cannot be nested with <p> Tag.

您使用的标记是错误的。不能使用

标记嵌套

#3


0  

Try using

试着用

<div style="display: inline">

Otherwise, use <span> instead of <div>.

否则,使用而不是

#4


0  

From the HTML 4.01 specification section 9.3.1

来自HTML 4.01规范第9.3.1节

The P element represents a paragraph. It cannot contain block-level elements (including P itself).

P元素代表一个段落。它不能包含块级元素(包括P本身)。

#1


5  

An authoritative place to look for allowed containment relations is the HTML spec. See, for example, http://www.w3.org/TR/html4/sgml/dtd.html. It specifies which elements are block elements and which are inline. For those lists, search for the section marked "HTML content models".

查看允许的包容关系的一个权威的地方是HTML规范。它指定哪些元素是块元素,哪些是内联的。对于这些列表,搜索标有“HTML内容模型”的部分。

For the P element, it specifies the following, which indicates that P elements are only allowed to contain inline elements.

对于P元素,它指定以下内容,这表明P元素只允许包含内联元素。

<!ELEMENT P - O (%inline;)*            -- paragraph -->

This is consistent with http://www.w3.org/TR/html401/struct/text.html#h-9.3.1, which says that the P element "cannot contain block-level elements (including P itself)."

这与http://www.w3.org/TR/html401/struct/text.html#h-9.3.1是一致的,它说P元素“不能包含块级元素(包括P本身)”。

Why <p> tag can't contain <div> tag inside it?

为什么

标签不能包含

标签?

#2


1  

The markup you use is wrong. The <div> cannot be nested with <p> Tag.

您使用的标记是错误的。不能使用

标记嵌套

#3


0  

Try using

试着用

<div style="display: inline">

Otherwise, use <span> instead of <div>.

否则,使用而不是

#4


0  

From the HTML 4.01 specification section 9.3.1

来自HTML 4.01规范第9.3.1节

The P element represents a paragraph. It cannot contain block-level elements (including P itself).

P元素代表一个段落。它不能包含块级元素(包括P本身)。