开发者

jquery: attach after each <div id='d[anumber]' >asdfa<div/> a <a href="javascript:Add(d[anumber]) >add</a>

开发者 https://www.devze.com 2022-12-29 13:57 出处:网络
I have something like this: <div id=\'d12\'>content</div> <div id=\'d23\'>content</div>开发者_开发百科;

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);
    }
});
0

精彩评论

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