A
A
agent11562016-09-22 18:35:48
JavaScript
agent1156, 2016-09-22 18:35:48

How to write js as yii2?

<?php
$js = <<<JS
$(function () {

            $("p").css(
            {
                color: "green",
                backgroundColor: "lightgray"
            });

        })
    
JS;

$this->registerJs($js);

?>

Where is the mistake ??

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
holfza, 2016-09-22
@holfza

Maybe a gap is needed here?
<<< JS

R
Rou1997, 2016-09-23
@Rou1997

I prefer "standard":

...
?>
<script>
...
</script>
<?php
...

<<< JSIt makes sense to use it only if this script will be "attached" to the widget being created that provides for this, that is, if you want to process the script on the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question