Loading li tags into ul tag using JQuery
I have an empty unordered list in my design. Now I want to add the following to the ul
element:
<li>
<div class="item left">开发者_运维问答;
<div class="wrap">
<h2>Test Header1</h2>
<p>Test Copy</p>
<p><a class="button" href="#">Click here</a></p>
</div>
<img src="images/bubble.jpg" width="248" height="211" class="right" />
</div>
</li>
With the setInterval
, I want to append another li
element/content to the ul
element without deleting the first li
added. How do I achieve this using jQuery?
Use .append: $('ul').append('<li>....</li>');
Look into .append for this, eg: $("ul").append(li_html_here);
Just bear in mind that you'll want to specify the ul with more than just $("ul") else you'll append that li to every ul on the page (eg: add an ID).
- Re-write Your Code as follows
<li class="firstli">
<div class="item left">
<div class="wrap">
<h2>Test Header1</h2>
<p>Test Copy</p>
<p><a class="button" href="#">Click here</a></p>
</div>
<img src="images/bubble.jpg" width="248" height="211" class="right" />
</div>
</li>
- And use the below:
$('ul').append($('.firstli'));
精彩评论