Working with Client Scripts
===========================
Modern web applications, additionally to static HTML pages that are
rendered and sent to the browser, contain JavaScript that is used
to modify the page in the browser by manipulating existing elements or
loading new content via AJAX.
This section describes methods provided by Yii for adding JavaScript and CSS to a website as well as dynamically adjusting these.
## Registering scripts
When working with the [[yii\web\View]] object you can dynamically register frontend scripts.
There are two dedicated methods for this:
- [[yii\web\View::registerJs()|registerJs()]] for inline scripts
- [[yii\web\View::registerJsFile()|registerJsFile()]] for external scripts
### Registering inline scripts
Inline scripts are useful for configuration, dynamically generated code and small snippets created by reusable frontend code contained in [widgets](structure-widgets.md).
The [[yii\web\View::registerJs()|registerJs()]] method for adding these can be used as follows:
```php
$this->registerJs(
"$('#myButton').on('click', function() { alert('Button clicked!'); });",
View::POS_READY,
'my-button-handler'
);
```
The first argument is the actual JS code we want to insert into the page.
It will be wrapped into a `