Show/hide Div


i would like to show/hide Div ,whenever i click on a button/Link or ajaxLink if needed.

Please tell me the best way to do it in yii.


Use javascript,On button onclick event ,make #divname.toggle(),so if it is show,than will make it hide,and vice versa,or you can simply write or #divname.hide().

how to use java script and where to keep it .Do i need to download toggle js?

Can you please provide me sample code.

Pretty simple example for You:

Yii::app()->clientScript->registerScript('name', "".





Perhaps useful to know, is that Yii comes bundled with jQuery (and many other great packages), but it’s not enabled by default. It will be registered in you html <head> section when using a widget on your page that relies on it, but if you’re not using one, you should register it manually.

So a slightly safer way of doing this, would be to prepend the code mentioned by mirunho, with:



  • framework/web/js/packages.php for the full list of available core scripts (aka. packages)

  • CClientScript Class

Didn’t help me sorry not very good into it.

can anybody tell me how does it yii i want the same. as given screen shot.4038


I am doing in this way.

<?php echo CHtml::Link(‘Genre’);

    Yii::app()-&gt;clientScript-&gt;registerScript('jquery', &quot;&quot;.&quot;&#036;('Genre').click(function(){&quot;.



""); ?></b>

    &lt;div id=&quot;ajaxgenre_view&quot; style=&quot;display:none&quot;&gt;

        Hi Shivanshu this is _view.php Media form.


Hi shivanshu,

You can try:

echo CHtml::link('genre', '#', array('class'=>'css_genre_class')); 

        Yii::app()->clientScript->registerScript('showGenre', ""."$('css_genre_class').click(function(){".



"");      ?></b>


        <div id="ajaxgenre_view" style="display:none">

            Hi Shivanshu this is _view.php Media form.


And please use code snippet for the next time.

Have a nice day.