son.of.the.morning Posted December 15, 2011 Share Posted December 15, 2011 I am trying to create a each() function to view individual modals in a php while loop. open modal <script type='text/javascript'> jQuery(function ($) { $('.basic').click(function (e) { $('#basic-modal-content').modal(); return false; }); }); </script> I tried this but it's not working (.record_i looped div container holding the hidden Div (modal) ) <script type='text/javascript'> $('.Record_i').each(function() { var obj_modal = $(this); jQuery(function ($) { $('.basic',obj_modal).click(function (e) { $('#basic-modal-content',obj_modal).modal(); return false; }); }); }); </script> Any ideas? Quote Link to comment Share on other sites More sharing options...
requinix Posted December 15, 2011 Share Posted December 15, 2011 The jQuery() stuff is about making $ available (if it were not before). As such it needs to be the outermost function call; everything else goes inside. Quote Link to comment Share on other sites More sharing options...
son.of.the.morning Posted December 15, 2011 Author Share Posted December 15, 2011 I got on to that a few moments ago and tried the code below... but it still ante having non of it i cant see were am going wrong at all jQuery(function ($) { $('.basic').each(function() { var obj_click = $(this); $('.basic',obj_click).click(function (e) { $('#basic-modal-content').each(function() { var modal = $(this); $('#basic-modal-content',modal).modal(); return false; }); }); }); }); Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 15, 2011 Share Posted December 15, 2011 What exactly is this script supposed to do? Quote Link to comment Share on other sites More sharing options...
son.of.the.morning Posted December 15, 2011 Author Share Posted December 15, 2011 I am using a jquery modal function but i have a loop of records and in the loop i have a button which i want to view a model with the corresponding data for each item returned in the while loop. Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 16, 2011 Share Posted December 16, 2011 So why not do something like this? $(document).ready(function(){ $('.basic').click(function(){ $(this).children('div.hidden').modal(); }); }); <style type="text/css">.hidden { display:none; }</style> <div class="basic"> <div class="hidden">Lorem Ipsum</div> </div> Quote Link to comment Share on other sites More sharing options...
son.of.the.morning Posted December 16, 2011 Author Share Posted December 16, 2011 I would but i need the .basic item to be a href Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 16, 2011 Share Posted December 16, 2011 So then do this: $(document).ready(function(){ $('.basic').click(function(e){ e.preventDefault(); $(this).children('div.hidden').modal(); }); }); <style type="text/css">.hidden { display:none; }</style> <a class="basic"> <div class="hidden">Lorem Ipsum</div> </a> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.