正确的jQuery选择器中的结束标记 [英] Correct closing tag in jQuery selector
问题描述
这是我在网上看到的一小段代码,我想知道<p/>
是拼写错误还是什么
Here's a snippet of code I saw on the web and I'm wondering if the <p/>
is a typo or what
'config' : {
'content' : $('#topGlobal')
},
topGlobal.$content= topGlobal.config.content;
topGlobal.$sections = topGlobal.$content.
find('ul.sections > li');
topGlobal.$side_nav = $('<p/>')
.attr('id','side_nav ')
.prependTo(topGlobal.$content);
topGlobal.$item_nav = $('<p/>')
.attr('id','item_nav')
.insertAfter(topGlobal.$side_nav);
...
在此代码的其他几个部分中重复了<p/>
.这听起来像一个愚蠢的问题,虽然我没有测试过,但我知道<p></p>
是正确的HTML.但是,由于作者是受人尊敬的JS作者,所以我要问.这可能是一个错字,但我仍然想知道为什么代码选择了结束标记.
The <p/>
is repeated in several additional parts of this code. This may sound like a stupid question and while I haven't tested it, I know <p></p>
is correct HTML. But because the author is very well respected JS author, I'm asking. It's probably a typo, but I'd still like to know why the code is selecting the closing tag.
推荐答案
<p/>
是可用于jQuery的快捷方式,用于创建新的HTML元素实例.在这种情况下,是段落元素.
<p/>
is a shorthand you can use in jQuery to create a new HTML element instance. In this case, a paragraph element.
这篇关于正确的jQuery选择器中的结束标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!