Reputation: 393
Hi i am using Ajax to get a SELECT tag. I mean, if i click on a button it will generate a SELECT tag inside HTML, i have different outputs for different options of select.
I need an onclick event on that SELECT tag, i tried using JQuery
$('#id').click(function() {
alert('test');
});
Its not working. Can anybody help, please
Upvotes: 4
Views: 1115
Reputation: 15835
as you are dynically generating html use live instead of click
$('#id').live('click', function() {
// Live handler called.
});
Upvotes: 2
Reputation: 22438
Because the select tag is dynamically added to the HTML after the event was set, the event is not set on the select tag.
A simple solution is to use live()
here:
$('#id').live('click', function() {
alert('test');
});
Upvotes: 3
Reputation: 4749
Make sure
id
id to one and only one item on your page,Upvotes: 0