I have something like this:
<div id='d12'>content</div>
<div id='d23'>content</div>开发者_开发百科;
<div id='d34'>content</div>
and I would like to insert a link after each link like this
<div id='d12'>content</div><a href='javascript:add(d12)'/>add</a>
$('div[id^=d]').each(function(){
$(this).after(
"<a href='javascript:add(" + $(this).attr("id") + ")'>add</a>"
);
});
$('div').each(function() {
var id = $(this).attr('id');
if (id.match(/^d\d+$/)) {
$('<a />')
.text('add')
.attr('href', '#')
.click(function() {
add(id);
return false;
})
.insertAfter(this);
}
});
精彩评论