onClick attribute striped out in rendered html
Try this code:
$form['cancel'] = [
  '#markup' =&gt; '&lt;div class=&quot;left&quot;&gt;&lt;a onClick=&quot;javascript:back_callback(1);&quot; href=&quot;javascript:void(0)&quot; class=&quot;back_btn&quot;&gt;' . t('Back') . '&lt;/a&gt;&lt;/div&gt;',
];
$form['step2_submit'] = [
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Next'),
  '#prefix' =&gt; '&lt;div class=&quot;right&quot;&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
  '#name' =&gt; 'step2',
  '#attributes' =&gt; ['class' =&gt; ['enabled-for-ajax']],
  '#ajax' =&gt; [
    'callback' =&gt; '::myajaxmethod',
  ],
];