Show/hide Div

Hi,

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.

Thanks

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 #divname.show() 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', "".

"$('.class_name').click(function(){".

		"$('#div_id').toggle();".

"});".

"");

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:




Yii::app()->clientScript->registerCoreScript('jquery');



See

  • 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 work.in yii i want the same. as given screen shot.4038

Untitled.png

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;.


            &quot;&#036;('#ajaxgenre_view').toggle();&quot;.

"});".

""); ?></b>

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


        Hi Shivanshu this is _view.php Media form.


    &lt;/div&gt;

Hi shivanshu,

You can try:


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

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

                "$('#ajaxgenre_view').toggle();".

"});".

"");      ?></b>

        

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

            Hi Shivanshu this is _view.php Media form.

        </div>

And please use code snippet for the next time.

Have a nice day.

DM.