Adding a javascript inside my view results in the ReferenceError: $ is not defined
. I assume that the problem is due to Yii2 injects scripts last on my page. How to fix this?
Or how will I prevent Yii2 from autoloading the script files?
My view
<?php
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\helpers\UrlManager;
use yii\widgets\ActiveForm;
use backend\controllers\StandardController;
use backend\models\standard;
?>
<div class="domain-form">
<?php $form = ActiveForm::begin(); ?>
<?php
<?= $form->field($model, 'clause')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'name')->textarea(['rows' => 6]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<script type="text/javascript">
$("document").ready( function () {
alert("hi");
});</script>
I need to get this simple script to show an alert after the page loaded. I hav'nt called any of the script file here since yii loads automatically(i think) in the layout by calling
AppAsset::register($this);
This results in script files to be registered at the end of the page,after my custom script.
How to solve this?