Reputation: 11619
I have a weird problem with this javascript (ldelim and rdelim are for curly braces when using smarty)
$('#bouton').on('click',function() {ldelim}
event.preventDefault();
$.post(url,data,function(callback_data){ldelim}
....
{rdelim});
{rdelim});
this script will reveal a div tag ('#thisdiv') that was invisible. Then I added
$('#thisdiv').on('click',function() {ldelim}
event.preventDefault();
$.post(url,data,function(callback_data){ldelim}
....
{rdelim});
{rdelim});
But nothing is happening on the click on '#thisdiv' (even if I suppress anything in the click function on '#thisdiv' and put an alert message). Someone could help ?
Edit : before the first call there is , after the first call the class 'invisible' us removed (class 'invisible' is a display none class)
Upvotes: 1
Views: 112
Reputation: 136164
#thisdiv
does not exist when this code runs - so it cannot attach the event. You need to delegate higher up the document. For example:
$(document).on('click','#thisdiv',function(){...});
or if there is a parent element that is there on load, you could use this as the anchor:
$('#theparent').on('click','#thisdiv',function(){...});
Upvotes: 4