I have this HTML code and it works perfect:
<a href="www.link.com"><img onmouseover="this.src='http://www.example.com.img1.jpg';" onmouseout="this.src='http://www.example.com.img2.jpg';" src="http://www.example.com.img2.jpg" alt="ALT Text" class="img-responsive"/></br></a>
I want to add this code in PHP and replace the link and image urls with this variables: $link, $image_src1 and $image_src2.
I tried this code:
<a href=".$link."><img onmouseover="this.src='.$image_src1.';" onmouseout="this.src='.$image_src2.';" src=".$image_src2." alt="ALT Text" class="img-responsive"/></br></a>
I think I can not manage how to use quotes, because of this, I am getting an error.
Thank you in advance!
Try this:
$link = 'http://www.google.com';
$image_src1 = "https://image.flaticon.com/icons/svg/148/148766.svg";
$image_src2 = "https://image.flaticon.com/icons/svg/149/149147.svg";
echo '<a href="'.$link.'"><img onmouseover="this.src='.$image_src1.';" onmouseout="this.src='.$image_src2.';" src="'.$image_src2.'" alt="ALT Text" class="img-responsive"/></br></a>';
But you really need to look in your code logic, for mouseover/out. You can achieve same logic using CSS :hover
property in simple and elegant way.