0

I have JQuery code to change a css of ID. If I use event hover, it runs well. But when I change it to a click event, it doesn't work, there is even nothing showing up in the console log. I have created a snippet here:

$(document).ready(function(){
	$("#donatenow").click(function(){
	console.log("klik klik");
		$("#subdonate").show();
		}, function(){
		$("#subdonate").hide();
	});
});
.subdonate{
	float:left;
	margin-top:-45px; 
	display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<img src="http://buymebook.com/assets/cat/School%20and%20College%20Text%20Books.jpg" style="margin:20px;" class="promo3" id="donatenow" /><br />
			<div class="subdonate" id="subdonate">
				<a href="#"><img src="http://p3cdn4static.sharpschool.com/UserFiles/Servers/Server_1110080/Image/books.jpg" style="margin:20px;" class="promo3" /></a><br />
				<a href="#"><img src="http://p3cdn4static.sharpschool.com/UserFiles/Servers/Server_1110080/Image/books.jpg" style="margin:20px; margin-top:-25px;" class="promo3" /></a>
			</div>

Does anyone know why my jquery fails? What I want is, when I click the first image, the second and third image show up, but when I click again, the second and third image will hide again.

1 Answer 1

1

Try this one.

here's an example: http://jsfiddle.net/aqm7kjbg/4/

just change your jquery.

var count = 1;
$("#donatenow").click(function(){

    if(count % 2){
        $("#subdonate").show();
        count = count + 1;
    }else{
       $("#subdonate").hide();
        count = 1;
    }

});
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect! So the problem is click event can use 2 event at once? Because if I use hover, it works good. I can accept Your answer in 8 minutes. Thank You
@CrossVander yes... don't forget to check if this helps you... =) happy coding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.