Search code examples
javascriptjquery-selectorsjqueryjquery-effects

help me for add input in jQuery


i have tow input, style column and mediumCell. i want first input only have add, not add and remove together. also each input except first input have remove link and last input have add and remove together.

code: http://jsfiddle.net/cJACG/15/


Solution

  • This might help:

    $(function () {
                $('a.add_input').live('click', function (event) {
                    event.preventDefault();
                    var newDiv = $('.ai_service').find('div:first').clone();
                    newDiv.append('<a href="" class="remove_input">remove</a>')
                    newDiv.find('input').each(function () { $(this).val(''); });
                    $('div.ai_service:first div:last').before(newDiv);
                });
    
                $('a.remove_input').live('click', function (event) {
                    event.preventDefault();
                    $(this).closest('div').remove();
                });
            });