Ragu
Ragu

Reputation: 27

Click Event for Dynamic Divs not Working

I have created divs with Click Event based on a value entered in a text box.

An Example Here

When you open the page and click any of the rows, you will get an alert. But when you change the value in the text box (Enter Number) and hit load button, then the rows will load based on the number entered.

Now when you click any rows, the click event does not work.....

Any Help in this regard is highly appreciated..........

Upvotes: 0

Views: 149

Answers (2)

Dave Anderson
Dave Anderson

Reputation: 12304

Your click handler for $('.schoolselect') is only attached once when the page loads. It is not a live jQuery event but that technique is deprecated in favour of the delegate model.

You can attach a delegate to $('#divHSSchoolResultTable') that will handle the clicks;

$('#divHSSchoolResultTable').delegate('.schoolselect', 'click', function() { alert(); });

See jQuery delegate for more details.

Upvotes: 1

Samsquanch
Samsquanch

Reputation: 9146

You need the live function.

$(".schoolselect").live("click", function() {

See here: http://jsfiddle.net/27Z3t/

Upvotes: 2

Related Questions