Swap image src?
I want to swap an image, form_arrow_down.jpg to form_arrow_up.jpg, when I click on an element, like this:
$(".c756:eq(0)").click(function(){
$("#wrapper_datorpaket").slideToggle("fast");
$("/images/18.296a9c501318fd486d1800013126/form_arrow_down.jpg").attr("src","/images/18.296a9c501318fd486d1800013126/form_arrow_up.jpg");
});
But I'm not sure I have done right at the line where the images swap, because it's not working!?
Add开发者_开发百科ing some of the markup:
<div class="c756">
<span class="h2">Datorpaket</span><br />
<span class="normal">text</span><br />
<div class="c89"><img alt="" src="/images/18.296a9c501318fd486d1800013126/form_arrow_down.jpg" /></div>
</div>
This does not work:
$("/images/18.296a9c501318fd486d1800013126/form_arrow_down.jpg")
Try:
$('img[src=/images/18.296a9c501318fd486d1800013126/form_arrow_down.jpg]')
Your code is not working since your selector is incorrect (pointing to an actual image):
$("/images/18.296a9c501318fd486d1800013126/form_arrow_down.jpg").attr("src","/images/18.296a9c501318fd486d1800013126/form_arrow_up.jpg");
You should reference the image element and change the attribute (As an example, if your element has the id: wrapper_datorpaket_image ) :
$("#wrapper_datorpaket_image").attr("src","/images/18.296a9c501318fd486d1800013126/form_arrow_up.jpg");
EDIT
This should work for you:
$('.c756 img').attr("src","/images/18.296a9c501318fd486d1800013126/form_arrow_up.jpg");
not sure about your code but much better way to achieve similar functionality is to use css to apply both images to your required element using different css class and then user jquery toggleClass to toggle between there two class when your click event occurs.
精彩评论