javascript - Pass variable to this.src -
i have name of image file generated in javascript , passed src of image in html - works.
i want pass image file onmouseover attribute of image. (because file name dynamically generated can't use hover in css).
var new_source_for_image = "/prestashop_1.7.0.3/modules/se_daynight/img/" + file_name + ".png"; }); }); </script> {/literal} <div id="visit_daynight"> <div class="change_visit"> <a href="#"><img id="visit_image" src="" width="350" height="350"></a> </div> </div>
so thought of adding variable generated file name:
var new_source_for_image_with_glow = "/prestashop_1.7.0.3/modules/se_daynight/img/" + file_name + "_glow" + ".png";
and:
<a href="#"><img id="visit_image" src="" width="350" height="350" onmouseover="this.src=???" onmouseout="this.src=???"></a>
but don't know how pass new variable in this.src attribute.
anybody have ideas?
much appreciated!
with jquery using mouseover()
, mouseout()
, attr()
methods.
$(document).ready(function(){ var file_name='your_file_name'; var new_source_for_image ="/prestashop_1.7.0.3/modules/se_daynight/img/" + file_name + ".png"; var new_source_for_image_with_glow = "/prestashop_1.7.0.3/modules/se_daynight/img/" + file_name + "_glow" + ".png"; $("img#visit_image").attr('src',new_source_for_image); $("img#visit_image").mouseover(function(){ $(this).attr('src',new_source_for_image_with_glow); }); $("img#visit_image").mouseout(function(){ $(this).attr('src',new_source_for_image); }); });
Comments
Post a Comment