0

Been going through these 3 lines for the past 15 minutes, but i just don't see it... EDITED CLASS NAMES. html

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

jquery

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

I've tried appending to .child, to .parent ul.child no luck

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.

user3638287
  • 43
  • 1
  • 13

1 Answers1

4

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?

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).

In additional:

As mentioned in comments to your question (and at w3cschools website):

Do NOT start a class name with a number!

So use this:

jQuery:

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

HTML:

<div class="parent" >
<ul class="child" style="height:auto !important"></ul>
</div>
Community
  • 1
  • 1
Sharikov Vladislav
  • 7,049
  • 9
  • 50
  • 87
  • This is more of a comment than an answer. – Jay Blanchard May 14 '14 at 20:11
  • @user3638287 I added demo which shows that your code is working fine (even with bad class name). Problem is not there. – Sharikov Vladislav May 14 '14 at 20:14
  • I have other names for classes. I used numbers to simplify, but i'll keep it in mind. thanks. What i don't get is when i look at fiddle you provided, it works. I copy the same code into separate fiddle and it fails – user3638287 May 14 '14 at 20:15
  • @user3638287 - Check your browser's console for errors. – j08691 May 14 '14 at 20:19
  • 1
    @user3638287 Yes, I updated my question, but forget to said about here. I added some suggestions about how to debug your js code. So do it. – Sharikov Vladislav May 14 '14 at 20:20
  • there is an error in console, but it's in a different file and a different script. Yes, i'm sure jquery is included. There is another jquery script, and it works fine. – user3638287 May 14 '14 at 20:34
  • What error? If you have some errors in jQuery console you have to solve problem. It can cause this error. + check selectors again. It is okay? Do it again. Still okay? Take a rest then :) The problem is not here, as I said. Your code is working fine. – Sharikov Vladislav May 14 '14 at 20:36
  • No. just went with a different solution... But thank you for your time! – user3638287 May 16 '14 at 01:57