开发者

onclick event on Ajax output

开发者 https://www.devze.com 2023-01-24 00:49 出处:网络
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.

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 开发者_StackOverflowneed an onclick event on that SELECT tag, i tried using JQuery

$('#id').click(function() {
  alert('test');
});

Its not working. Can anybody help, please


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


as you are dynically generating html use live instead of click

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


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. :)


live is now deprecated. Use on instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号