Applying styles from CSS to newly appended elements

后端 未结 3 688
太阳男子
太阳男子 2021-01-04 19:13

I add an element to a parent div dynamically.

$(\'.some_div\').append(\"
  • hey!
  • \")

    In my CSS,

    
    
            
    3条回答
    •  悲哀的现实
      2021-01-04 19:54

      You need to escape name of class here.

      Change

      $('.some_div').append("
    • hey!
    • ");

      to

      $('.some_div').append("
    • hey!
    • ");

      OR

      $('.some_div').append("
    • hey!
    • ");

      DEMO here.

      Demo with style:

      $('.some_div').append("
    • hey!
    • ");

      OR

      $('.some_div').append("
    • hey!
    • ").find("li:last").css("color","yellow");

      Demo here.

    提交回复
    热议问题