title: Drupal click event lost after d3js tree collapse
body: <p>d3js (both v4 and also v3) charts in Drupal 7 with having click event attached to one of the svg text element using <code>.attr("class", "ajax_button")</code> and attaching Drupal behavior for that element. Problem is that click event is lost once tree gets collapsed and not get reattached on expand.<br>
  link : <a href="http://firststateindia.org/d3v4-test-wrapper" rel="nofollow noreferrer" title="d3js + drupal behavior">d3js + Drupal behavior</a><br>
  following is code for click element  </p>
  
  <pre><code>    (function($) {
  
      Drupal.behaviors.listload = {
  
          attach: function(context, settings) {
  
              if (context == document) {
                  $('.ajax_button', context).once(function() {
                      $(this).click(function(e) {
                          e.preventDefault();
                          // https://stackoverflow.com/a/1369080
                          // to prevent collapsible function which is attached to parent element
                          e.stopPropagation();
                          var the_id = $(this).attr('href'); // contextual filter(nid) to views
                          noSlashes = the_id.replace(/\//g, '');
  
                          $.ajax({
                              url: Drupal.settings.basePath + 'views/ajax',
                              type: 'post',
                              data: {
                                  view_name: 'candidate_list_er', //view name
                                  view_display_id: 'candidate_list_block', //your display id
                                  view_args: noSlashes, // your views arguments, //view contexuall filter
                              },
                              dataType: 'json',
                              success: function(response) {
                                  //console.log(response);
                                  if (response[1] !== undefined) {
                                      //console.log(response[1].data); // do something with the view
                                      var viewHtml = response[1].data;
                                      $('#ajax-target .content').html(viewHtml);
                                      //Drupal.attachBehaviors(); //check if you need this.
                                  }
                              },
                              error: function(data) {
                                  alert('An error occured!');
                              }
                          });
  
                      }); //click ends
                  }); //once ends
              }
          },
          detach: function(context, settings, trigger) { //this function is option
          $('.ajax_button').unbind(); //or do whatever you want;
          }
      };
  
  })(jQuery);
  </code></pre>