javascript - jQuery .delegate not working -


the following code works toggle class when page loads, not work after ajax call.

the html ([field_map_location] drupal token):

<div class="clearfix dir-map"> <a href="#" class="show">map</a> <div id="slidingdiv" class="outside"> [field_map_location] </div> </div> 

the javascript:

<script type="text/javascript">  jquery(function($) { $(document).ready(function() {     $('.dir-map').delegate('a', 'click', function(e) {         e.preventdefault();          $(this).next('div').toggleclass('outside inside');     }); });  }); </script> 

update i've tried following recommended solution , still not work.

<script type="text/javascript">  jquery(function($) {     $(document).delegate('.dir-map a', 'click', function (e) {         e.preventdefault();          $(this).next('div').toggleclass('outside inside');     }); }); </script> 

sorry, i'm noobie, don't know how present code ajax call. can tell html part of drupal view , i'm using ajax capability.

drupal can funny ajax @ times; hooking drupal's own js behaviors system might help...

(function($) {   drupal.behaviors.custom = {     attach: function(context, settings) {       $('.dir-map a', context).click(function (e) {         e.preventdefault();          $(this).next('div').toggleclass('outside inside');       });     }   }; })(jquery); 

the archaic event attaching because drupal 7 still ships jquery 1.4.2.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

What is the difference between data design and data model(ERD) -

ios - Can NSManagedObject conform to NSCoding -