Reputation: 262
Path for image- assets/rating/star.png Now how to give this path in external js I have also loaded the url helper.
$(document).ready(function(){
$("#1_star").hover(function(){
$("#1_star").attr("src","Path for image");
});
});
I am doing this way
$(document).ready(function(){
$("#1_star").hover(function(){
$("#1_star").attr("src","<?php echo base_url('assets/rating/star.png');?>");
});
});
Upvotes: 0
Views: 912
Reputation: 1146
in your html page add
<input type="hidden" id="document" name="document" value="<?php echo base_url('assets/rating/star.png');?>">
In your js file
var path= $('#document').val();
alert(path);
$(document).ready(function(){
$("#1_star").hover(function(){
$("#1_star").attr("src",path);
});
});
try and let me know it works or not
Upvotes: 1
Reputation: 721
Try this:
$(document).ready(function(){
$("#1_star").hover(function(){
var base_url = window.location.origin;
$("#1_star").attr("src",base_url + '/assets/rating/star.png');
});
});
Upvotes: 2