我的HTML
//box one
<div class="blog-module">
<h3>Title of Blog</h3>
<div class="blog entry">
Each blog post in here.
</div>
<div class="blog entry">
Each blog post in here.
</div>
<div class="more">
<a href="link.com">Read more</a>
</div>
</div>
//box two
<div class="blog-module">
<h3>Title of Blog</h3>
<div class="blog entry">
Each blog post in here.
</div>
<div class="blog entry">
Each blog post in here.
</div>
<div class="more">
<a href="link.com">Read more</a>
</div>
</div>
使用jQuery,我想找到每个 .more a href并在每个 .blog-module div中生成 h3 标记点击它。 感谢
答案 0 :(得分:0)
$('.more a', '.blog-module').each(function(index, link){
var $link = $(link);
var $headingLink = $('<a/>');
$headingLink.attr('href', $link.attr('href'));
var $heading = $('h3', $link.parent().parent());
$headingLink.append($heading.clone());
$heading.replaceWith($headingLink);
});
答案 1 :(得分:0)
$('.blog-module').each(function(){
var SP_Link = $(this).find(".more a").attr('href');
var SP_Module_Name = $(this).find("h3").text();
$(this).find("h3").replaceWith ('<h3><a href="'+SP_Link+'">'+SP_Module_Name+'</a></h3>');
});