简体   繁体   English

无法使用Jquery将li附加到ul中

[英]Can't append li into ul with Jquery

Been going through these 3 lines for the past 15 minutes, but i just don't see it... EDITED CLASS NAMES. 在过去的15分钟内经历了这3条线,但我只是看不到...编辑的班级名称。 html HTML

<div class="parent" >
<ul class="child" style="height:auto !important"></ul>
</div>

jquery jQuery的

$(document).ready(function(){
$(".parent ul").append('<li>wtf</li>');
});

I've tried appending to .child, to .parent ul.child no luck 我尝试将.child附加到.parent ul.child之后

Edit: when i look at the fiddle in the answer bellow, it works. 编辑:当我看着下面的小提琴时,它起作用了。 I copy the same code and it fails. 我复制相同的代码,但失败。 I tried all browsers. 我尝试了所有浏览器。 same thing. 一样。

Your code: 您的代码:

$(document).ready(function(){
    $(".1 ul").append('<li>wtf</li>');
});

Works fine. 工作正常。

Demo 演示

Problem is not in code, you added to your question. 问题不在代码中,您已添加到问题中。 Are you sure you included jquery library? 您确定包含jquery库吗?

Please, use firebug tool or any other tool to debug your code (chrome developers tools (CTRL+SHIFT+J), developers tools in ie (possibly F12), developers tools in Firefox (CTRL+SHIFT+J). You can find some good answers here (read answers). 请使用firebug工具或其他任何工具来调试代码(chrome开发者工具(CTRL + SHIFT + J),ie中的开发者工具(可能是F12),Firefox中的开发者工具(CTRL + SHIFT + J)。您可以找到一些好的答案在这里 (阅读答案)。

In additional: 另外的:

As mentioned in comments to your question (and at w3cschools website): 如对您的问题的评论中所述(以及在w3cschools网站上):

Do NOT start a class name with a number! 不要以数字开头课程名称!

So use this: 所以使用这个:

jQuery: jQuery的:

$(document).ready(function(){
    $(".parent ul").append('<li>wtf</li>');
});

HTML: HTML:

<div class="parent" >
<ul class="child" style="height:auto !important"></ul>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM