How to create a DOM node as an object?

前端 未结 6 708
栀梦
栀梦 2020-12-07 20:04

I would like to create a DOM node, set the \'id\' attribute and then append it to \'body\'. The following seems not to work because jQuery doesn\'t see my template as an obj

6条回答
  •  青春惊慌失措
    2020-12-07 20:47

    And here is the one liner:

    $("
  • bla
  • ").find("li").attr("id","1234").end().appendTo("body")

    But I'm wondering why you would like to add the "id" attribute at a later stage rather than injecting it directly in the template.

提交回复
热议问题