Append anchor tag inside list-item

空扰寡人 提交于 2019-12-12 04:45:30

问题


I have an unordered list:

Html:

<ul id="blogs">
   <li>
     <a class="vimg" href="/blogs/news/6875583-hurricane-sandy">
      <img src="mydomainvideo_icons.jpg?1542">
    </a>
 </li>
    <a href="/blogs/news/6875583-hurricane-sandy">
      <strong class="titlen">Hurricane Sandy</strong>
      <p class="newsp">lorem ispum lorem ispumu...</p>
    </a>
    <a class="readp" href="/blogs/news/hurricane-sandy">Read More</a>
 <li></li>
 <li></li>
</ul>

I would like to alter the html above with jQuery, so the output would be the following:

  <ul id="blogs">
   <li>
      <a class="vimg" href="/blogs/news/6875583-hurricane-sandy">
       <img src="mydomainvideo_icons.jpg?1542">
     </a>
     <a href="/blogs/news/6875583-hurricane-sandy">
       <strong class="titlen">Hurricane Sandy</strong>
       <p class="newsp">lorem ispum lorem ispumu...</p>
    </a>
    <a class="readp" href="/blogs/news/hurricane-sandy">Read More</a>
 </li>
 <li></li>
 <li></li>

This is the jquery I have but its a not working:

jQuery:

  $("#blogs li").each(function(){

       if ($(".video-container").length > 0  && $(this).children('img').length == 0){
          var vidindex = $('.readp').attr('href')
          $(this).find('.video-container').remove();
          $(this).append('<a class="vimg" href=""><img src="{{ 'video_icons.jpg' | asset_url }}"/></a>');
          $('.titlen').appendTo('.vimg')
          $(this).find('a').attr("href", vidindex)
     }
      $(this).find('img').replaceWith(function(){ return '<img src="'+this.src+'"/>';});
});

回答1:


Append anchor tag inside list-item

$("#blogs").find("li").append("<a href='#'>some Description</a>");


来源:https://stackoverflow.com/questions/13355755/append-anchor-tag-inside-list-item

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!