Reputation: 133
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!?
Adding 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>
Upvotes: 0
Views: 135
Reputation: 7117
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");
Upvotes: 1
Reputation: 1680
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.
Upvotes: 0
Reputation: 108500
This does not work:
$("/images/18.296a9c501318fd486d1800013126/form_arrow_down.jpg")
Try:
$('img[src=/images/18.296a9c501318fd486d1800013126/form_arrow_down.jpg]')
Upvotes: 2