call jquery modal in dynamically generated <span> -


i'm trying open modal pop-up using dynamically generated content, far it's not working well. php code generates set of elements title of events, , when clicked on title, need open popup, again it's content dynamic.

following code:

<?php echo '<span id="rentalrates" name="rentalrates" ><u style="cursor:pointer;"><h2>'.$row["header"].'</h2></u></b></span> <div style="width:550px;overflow-y:auto;"  class="details"  id="divauditoriumguidelines"> <div id="divrentalrates'.$x.'"  title="rental rates" name = "divrentalrates'.$x.'"> <p>'.$row["longdescription"].'</p> </div>'; echo '</div> <div  class="closer"></div> </div> </li>'; $x = $x + 1; ?> 

following jquery:

$("#divrentalrates0").dialog( {     autoopen: true,     width: 750,     height: 650,     show:     {         effect: "blin",         duration: 1000     },     hide:     {         effect: "explode",         duration: 1000     } });  $("#rentalrates1").click(function() {     $("#divrentalrates0").dialog("open"); });  $("#rentalrates2").click(function() {     $("#divrentalrates0").dialog("open"); }); 

however, doesn't work. if put static modal popup outside looping, works fine. can me please?

$(document).on('click','#rentalrates1,#rentalrates1',function() {     $("#divrentalrates0").dialog("open"); }); 

the above code work, more specific,

use solution:

$(document).on('click','[id^="rentalrates"]',function() {     $("#divrentalrates0").dialog("open"); }); 

use event delegation - on()


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -