Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
34
rated 0 times [  35] [ 1]  / answers: 1 / hits: 19953  / 11 Years ago, sun, september 8, 2013, 12:00:00

this is going to be my first question so far cause i always do a research before using forums, but i dont get this to work.



I have an Image that works as a button for a toggle animation (button.png) and i want that image to change after clicking on it for another image (button2.png), and once you click the second image it changes again to the first image, i have:



<script type=text/javascript>
$(document).ready(function() {

// when click on the tag with id=btn
$('#btn').click(function() {
// change the state of the #idd
$('#idd').toggle(800, function() {
// change the button text according to the state of the #idd
if ($('#idd').is(':visible')) {
$('#btn').attr('images/button2.png', this.href); // Show Less.. button
} else {
$('#btn').attr('images/button.png', this.href); //Learn More.. button

}
});
});
});
</script>


and my Html:



<div id=idd style=display:none;>

- Here my hidden content -

</div>

<!-- Button -->
<img src=images/button.png style=cursor: pointer; id=btn>


What im doing wrong? Please Help :(


More From » jquery

 Answers
6

Check the syntax for .attr. It should be something like



$('#btn').attr('src', 'your image src'); 


Function Reference: http://api.jquery.com/attr/


[#75833] Thursday, September 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
havenbilliec

Total Points: 324
Total Questions: 106
Total Answers: 94

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;