0

I have my code here http://jsfiddle.net/NT4Zr/5/

In above code i am able to add new row but cant delete added row by clicking Delete link. How can i do that?

In hobbies section i want to add hobbies by writing into text box and add hobby button and it should be reflected to label

        <label>Your Hobbies:</label>

and by clicking delete button it should be deleted.

How can i do that?


Please refer this link

http://jsfiddle.net/NT4Zr/28/

as it works well but when i am adding school by typing school name and selecting year it will add new elements with same name. how can i create blank elements like this http://viralpatel.net/blogs/demo/dynamic-add-delete-row-table-javascript.html

How can i pass textbox value to the label in hobby section?

4
  • 2
    Argh. Yet another question asker who hasn't heard of .live(). Commented Oct 3, 2011 at 10:05
  • can you please explain it or attach some link? Commented Oct 3, 2011 at 10:12
  • 1
    here, here and here. Commented Oct 3, 2011 at 10:14
  • jsfiddle.net/NT4Zr/28 please find this link to answer my remaining question for add/delete hobby.. Commented Oct 3, 2011 at 10:15

3 Answers 3

2

event handlers do not get attached to the dynamically added elements to the DOM try using live

 $('.deleteEl a').live("click",function () {

DEMO

Sign up to request clarification or add additional context in comments.

Comments

1

As the element does not exist when you bind the click event, it is not associated. You need live to bind the event to dynamic elements.

http://jsfiddle.net/NT4Zr/19/

$('.deleteEl a').live('click', function () {
    $(this).parent().parent().remove();
});

Comments

1

Working example using delegate here: http://jsfiddle.net/jkeyes/KYrAE/1/

$("#Education").delegate(".deleteEl a", "click", function(){
        $(this).parent().parent().remove();
});

delegate is more efficient than live.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.