开发者

Dynamically adding li in ul? [closed]

开发者 https://www.devze.com 2023-02-22 16:24 出处:网络
It's difficult to tell what is being as开发者_JS百科ked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. F
It's difficult to tell what is being as开发者_JS百科ked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.
<ul class="name-email-list">
      <li>xxxx<strong> tttttt</strong><a href="#." class="icon-close"></a></li>
 </ul>


.appendTo()

jQuery documentation
First get your content and append it to some element:

$("<li>WhateverContent</li>").appendTo(".name-email-list");

.append()

jQuery documentation
First get some element and append it your content:

$(".name-email-list").append("<li>WhateverContent</li>");

As you can see either of them can be used. They work the opposite way. Use the one that's easier to understand.


$('.name-email-list').append('<li>New  li </li>')


You could use the .append() method:

$('ul.name-email-list').append('<li>xxxx<strong> tttttt</strong><a href="#." class="icon-close"></a></li>');


Use the append function:

$('ul.name-email-list').append('<li>xxxx<strong> tttttt</strong><a href="#." class="icon-close"></a></li>');

But beware, that you need to reference your ul in a way, that only the targeted ul is selected. e.g. by ensuring, that only one ul has this class, or by giving the ul an id.

0

精彩评论

暂无评论...
验证码 换一张
取 消