开发者

Loading li tags into ul tag using JQuery

开发者 https://www.devze.com 2023-01-17 04:28 出处:网络
I have an empty unordered list in my design. Now I want to add the following to the ul element: <li>

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


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

  1. And use the below:

$('ul').append($('.firstli'));

0

精彩评论

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