Johan Van Baak
Johan Van Baak

Reputation: 43

HTML Attribute CHtml::link

I know there's also another post with this kind of question. But there was no (correct) answer that's why i wanted to open a new one to help me and also other people who want to know this.'

In the code below i want to add an onmouseover to have an hover effect on the image, is this possible? If yes could you help me please out?

echo CHtml::link(CHtml::image($home['src'], $home['alt']), Yii::app()->getController()->createUrl("/admin"));

It's written in Yii framework and PHP. Thanks in advance!

THANKS EVERYONE WHO HELPED ME!

I am very grateful to you for this, and hopefully the people who need it and are reading this too. And thanks for the quick response!

This is the working code

 echo CHtml::link(CHtml::image($home['src'], $home['alt'],array("onmouseover" => "this.src='/LimeSurvey/styles/scanyours/images/home1.png';")), Yii::app()->getController()->createUrl("/admin"));

Upvotes: 2

Views: 2472

Answers (3)

5z- -
5z- -

Reputation: 161

you can add on image too

echo CHtml::link(CHtml::image($home['src'], $home['alt'],array('onmouseover'=>'your function'), Yii::app()->getController()->createUrl("/admin"));

Upvotes: 3

verisimilitude
verisimilitude

Reputation: 5110

The function CHtml::link takes a third parameter $htmlOptions which you can use to specify any additional HTML attributes to your link.

You have two ways to have the mouseover effect.

1) Use the onmouseover HTML attribute in your link.

echo CHtml::link(CHtml::image($home['src'], $home['alt']), 
Yii::app()->getController()->createUrl("/admin"), array('onmouseover' => 'someJavascriptFunc()'));

2) Assign an ID to your link and bind jQuery's mouseover to it.

echo CHtml::link(CHtml::image($home['src'], $home['alt']), 
    Yii::app()->getController()->createUrl("/admin"), array('id' => 'temp'));

JQuery Mouseover event::

$('#temp').mouseover(function() {
        //Your code goes here.
    });

Upvotes: 2

nvanesch
nvanesch

Reputation: 2600

You can use htmloptions for this. it basically adds attributes.

echo CHtml::link(
        CHtml::image($home['src'], $home['alt']), 
        Yii::app()->getController()->createUrl("/admin"),
        array("onmouseover" => "youronmouseovercall()")
);

http://www.yiiframework.com/doc/api/1.1/CHtml#link-detail

Another option would be to use a CSS mouseover

#yourlement:hover
{
  color: #f00;
}

or use something like jquery

$("#yourelement").mouseover(function(){
  // do whatever you want here.
});

for the CSS or Jquery mouseover you can add the id with htmloptions.

echo CHtml::link(
            CHtml::image($home['src'], $home['alt']), 
            Yii::app()->getController()->createUrl("/admin"),
            array("id" => "yourelement")
    );

Upvotes: 2

Related Questions