My html code is
<div id="starimg">
<a href="#" class="imgstar" onclick="ratingFunc()"><img src="images/star1.png" class="star" /></a>
<a href="#" class="imgstar" onclick="ratingFunc()"><img src="images/star1.png" class="star" /></a>
<a href="#" class="imgstar" onclick="ratingFunc()"><img src="images/star1.png" class="star"/></a>
<a href="#" class="imgdarkstar" onclick="ratingApp()"><img src="images/star2.png" class="star1"/></a>
<a href="#" class="imgdarkstar" onclick="ratingApp()"><img src="images/star2.png" class="star1" /</a>
</div>
my java script code is
function ratingFunc(){
if( $('.star').attr("src")=='images/star1.png'){
$(this).replaceWith("<img src='images/star2.png' class="star1"/>");
starcheck=true;
}
else{
$(this).replaceWith("<img src='images/star1.png' class="star"/>");
starcheck=false;
}
}
function ratingApp(){
if($('.star1').attr("src")=='images/star2.png'){
$(this).replaceWith("<img src='images/star1.png' class="star"/>");
starcheck=true;
}
else{
$(this).replaceWith("<img src='images/star2.png' class"star1"/>");
starcheck=false;
}
}
when i am clicking on image then these function are not working..please help me.
Thanks in advance.
Your function doesn’t know what does this
$(this)mean within.It does, but thats not what you are looking for 🙂
Replace
$(this)with$(".star")in first function andReplace
$(this)with$(".star1")in other function.and it will work fine.