bee
bee

Reputation: 393

onclick event on Ajax output

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

Answers (4)

ConRockets
ConRockets

Reputation: 46

live is now deprecated. Use on instead.

Upvotes: 0

kobe
kobe

Reputation: 15835

as you are dynically generating html use live instead of click

  $('#id').live('click', function() {
  // Live handler called.
          });

Upvotes: 2

Harmen
Harmen

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

pestaa
pestaa

Reputation: 4749

Make sure

  • you have jQuery script file is inserted in your html page,
  • you have assigned id id to one and only one item on your page,
  • you give us a link to see your page if nothing else helps. :)

Upvotes: 0

Related Questions