Onclick Ajax Output Event

Hi, I am using Ajax to get the SELECT tag. I mean, if I click the button, it will generate a SELECT tag inside the HTML, I have different outputs for different choices.

I need an onclick event for this SELECT tag, I tried using jQuery

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

Does not work. Can someone help please

+3
source share
3 answers

Because the select tag is dynamically added to the HTML after the event has been set, the event is not set in the select tag.

A simple solution is to use live()here:

$('#id').live('click', function() {
  alert('test');
});
+2
source

html, live,

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

,

  • you have a jQuery script file that is pasted into your html page,
  • you have assigned idid to one and only one element on your page,
  • you give us a link to see your page if nothing helps. :)
0
source

Source: https://habr.com/ru/post/1773885/


All Articles