php - JQuery .click() triggers after the second click only -


i'm trying use jquery load() instead of javascript ajax. have multiple of ids generated each div php loop.

when creating jquery function below pass generated ids of divs fine but, have click twice on button in-order .click() event trigger , put window.alert() inside .click() function , popups twice after second click on button, idea how correct way?

updated

function updatedivs(generatedid){     $('#'+generatedid).click(function(){         //do .load() stuff     }); }  <?php  for($i=0 ; $i < 20 ; $i++){    $gen = mt_rand(100,999); ?>    <div id="<?=$gen;?>" onclick="updatedivs(<?=$gen;?>) > content </div <?php } ?> 

i think easiest way set class divs , inside can div id event.target.id.

i think problem need have document.ready() or $(function() { });

<div id="div_id" class="mydiv"> content </div> <script type="text/javascript">            $(document).ready(function () {         $(".mydiv").click(function (event) {             alert(event.target.id);         });     }); </script> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -