Basic Image Swap on Mouseover
Hello all!
I'm pretty new to front UI developement and have been using JQuery for about 6 months. Love it so far!
I am trying to get a image to swap out on mouseover and then go back on mouseout. I found a basic example StackTrace but I cannot seem to get it to work. When I mouseover, the image's scr changes to:
assets/images/photo1
undefined...
I'm hoping another set of eyes can spot the issue and provide guidance. Thanks!!
- <img src="assets/images/photo-1.jpg" id="imgBrand1" />
-
- <script src="assets/javascript/jquery-2.1.1.js"></script>
- <script>
- $('document').ready(function ()
- {
- $(function ()
- {
- $("#imgBrand1")
- .mouseover(function ()
- {
- var src = $(this).attr("src").match(/[^\.]+/) + "assets/images/photo-2.jpg";
- $(this).attr("src", src);
- })
- .mouseout(function ()
- {
- var src = $(this).attr("src").replace("assets/images/photo-2.jpg");
- $(this).attr("src", src);
- });
- });
- });
-
- </script>
-
Viewing source shows me (on mouseover)...
<img src="assets/images/photo-1undefinedundefinedundefinedundefined" id="imgBrand1">
Thanks!