jquery - How to execute JavaScript function in an Ajax() Response -


i have home page load ajax() response , post ul li content, same page have script function can select li content trigger function, isn’t working.

page 1

html

<ul id="feature-deals" class="list-products allshopping-deals">          </ul> 

script

$(document).ready(function(){     $.ajax({         url: "product/shopping-trending-items.php",          success: function(result){             $(".allshopping-deals").html(result);         }     });  $(".products").click(function (){            alert ($('.pid', this).text()); 

page 2

html

  <li class="products"> <span class="pid">1234</span> </li> 

page 1 == home page w/(ajax() load function + click function) ----> page 2 == li content holding pid , waiting load ajax() ----> target output alert pid value script in page 1

you should delegate event:

$(".allshopping-deals").on('click', '.products', function(){     alert($(this).find('.pid').text()); }); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -