Bhargav
Bhargav

Reputation: 451

how can i delete dynamic elements from My html page using Jquery?

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?

Upvotes: 0

Views: 670

Answers (3)

John Keyes
John Keyes

Reputation: 5604

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.

Upvotes: 1

Jayendra
Jayendra

Reputation: 52769

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

Upvotes: 1

Rafay
Rafay

Reputation: 31033

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

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

DEMO

Upvotes: 2

Related Questions