[英]Jquery html() method not working if we place a div inside a p tag?
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
). 我需要找到accordionContentTwoCol
div的html内容(我只能访问accor
)。
If i try to print html inside accordionContentTwoCol div like this: 如果我尝试在accordionContentTwoCol div中打印html,如下所示:
alert("html inside accordionContentTwoCol :"+$('.accor').next().html());
It gives output like this: 它提供如下输出:
Though HTML inside accordionContentTwoCol
is: 虽然accordionContentTwoCol
中的HTML是:
<p class="noEdit">
<div> name : </div>
</p>
why that happens? 为什么会这样?
An authoritative place to look for allowed containment relations is the HTML spec. 查找允许的包含关系的权威位置是HTML规范。 See, for example, http://www.w3.org/TR/html4/sgml/dtd.html . 例如,参见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内容模型”的部分。
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? 为什么<p>标签里面不能包含<div>标签呢?
The markup you use is wrong. 你使用的标记是错误的。 The <div>
cannot be nested with <p>
Tag. <div>
不能与<p>
标签嵌套。
Try using 尝试使用
<div style="display: inline">
Otherwise, use <span>
instead of <div>
. 否则,请使用<span>
而不是<div>
。
From the HTML 4.01 specification section 9.3.1 从HTML 4.01规范第9.3.1节
The P element represents a paragraph. P元素代表一个段落。 It cannot contain block-level elements (including P itself ). 它不能包含块级元素 (包括P本身 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.