title: Using Pjax in YII2 for updating a div
body: <p>I'm trying to use <strong>Pjax</strong> widget in a <strong>yii2</strong> project.<br>
  My goal is to update the <code>div #formsection</code> with some content.<br>
  My code:
  View</p>
  
  <pre><code>&lt;?php Pjax::begin(); ?&gt;
     &lt;div id="formsection"&gt;&lt;/div&gt;
     &lt;?php foreach ($tree as $id =&gt; $name): ?&gt;
          &lt;?php echo Html::a(
              $name, 
              ['update', 'id'=&gt;$id],
              ['data-pjax'=&gt; '#formsection']) ?&gt;
     &lt;?php endforeach ?&gt;
  &lt;?php Pjax::end(); ?&gt;
  </code></pre>
  
  <p>Update action</p>
  
  <pre><code>public function actionUpdate($id)
  {
      return $this-&gt;renderAjax('update');
  }
  </code></pre>
  
  <p>When I click the link all of the <code>pjax div</code> contents are replaced by the response from the server. I want just the <code>#formsection</code> content to update.</p>
  
  <p>I found a post <a href="http://www.yiiframework.com/forum/index.php/topic/54074-pjax-update-content-inside-a-div/U" rel="noreferrer">here</a> but it doesn't work too.</p>
  
  <p>Some more info:
  This is the js code that Pjax widget generates in the page.</p>
  
  <pre><code>jQuery(document).ready(function () {
  jQuery(document).pjax("#w0 a", "#w0", {"push":true,"replace":false,"timeout":1000,"scrollTo":false});
  jQuery(document).on('submit', "#w0 form[data-pjax]", function (event) {jQuery.pjax.submit(event, '#w0', {"push":true,"replace":false,"timeout":1000,"scrollTo":false});});
  });
  </code></pre>
  
  <p>What is the problem with my code?</p>
  
  <hr>
  
  <p>I solved the problem. I had to change the view to this.</p>
  
  <pre><code>&lt;div id="categories"&gt;
      &lt;?php foreach ($tree as $id =&gt; $name): ?&gt;
          &lt;?php echo Html::a(
                  $name, 
                  ['update', 'id'=&gt;$id],
                  ['data-pjax'=&gt; '#formsection']) ?&gt;
      &lt;?php endforeach ?&gt;
  &lt;/div&gt;
  &lt;?php Pjax::begin(['id'=&gt;'formsection', 'linkSelector'=&gt;'#categories a']); ?&gt;
  &lt;?php Pjax::end(); ?&gt;
  </code></pre>