Hide and Show texts of paragraph by clicking an image?

Hi guys

I know this is very easy.
But I’m a little rusty with jQuery.

Let say I have one image and below it are texts (paragraphs).

Now I want the texts to hide first.
When the image is clicked the texts will show-up.
How to do this?

Thanks in advanced.

Hi,
Do you want to do this just once, or have the paragraph hide/show every time you click on the image?

just once is fine.

I’m currently experimenting but I have no luck.


		$(document).ready(function(){
		   $("div #wu_message").hide();
		 
		   $("img #westerunion").click(function(){
		     $("#wu_message").show();
		   });
		});

#wu_message is the ID of a <div> where the texts reside.
#westerunion is the ID of the image <img>.

As you can see I’m trying to hide the texts first and will show when the image is clicked.

But it doesn’t work. Why?

Just remove the space in your selectors, i.e. div#wu_message and img#westerunion, or just leave out the div and the img altogether.

Also use $(this) to refer to the clicked element:

$(document).ready(function(){
  $("div #wu_message").hide();
		
  $("img #westerunion").click(function(){
    $("#wu_message").show();
  });
});

I already tried both,


		$(document).ready(function(){
		   $("#wu_message").hide();
		 
		   $("#westerunion").click(function(){
		     $("#wu_message").show();
		   });
		});

and


		$(document).ready(function(){
		   $("div#wu_message").hide();
		 
		   $("img#westerunion").click(function(){
		     $("div#wu_message").show();
		   });
		});

The obvious flaw is, It suppose to hide the texts first.
But it did not.

Can you post your HTML.

http://coder9.com/dr/front/payment_page

thanks in advanced pullo.

You need to put your code after you have included jQuery.
Put it just before the closing </body> tag and all will be well :slight_smile:

cool it works by hiding first the texts.
But when I clicked the western union image it doesn’t show the text.

?

Ooop just wrong spelling.

All works fine now.

Thanks pullo