InquilineKea
InquilineKea

Reputation: 891

How to hide individual paragraph elements on jquery?

So here is my site: http://alexkchen.me/agingquestions.php

I'd like to hide the paragraph below "Where can I pursue the study of aging?" when I click "Where can I pursue the study of aging?" (but only that paragraph).

I'd like to hide the paragraph below "What is the mTOR pathway?" when I click "What is the mTOR pathway?".

(ultimately I'd also like to expand out those paragraphs if I click the headers again).

How would I do this with jquery?

Upvotes: 0

Views: 54

Answers (3)

muni
muni

Reputation: 1360

hi followoing jquery script i will help you do the functionality you required.

$("h4").click(function(){
    $(this).next('p').toggle();
});

Please refer following js fiddle.

http://jsfiddle.net/664mj0qp/

Upvotes: 1

anto
anto

Reputation: 73

You could do something like this:

$("h4").click(function() { 
  $(this).next("p").toggle();
});

Also, it would be a good idea to use classes to better target the elements.

Upvotes: 1

Matt Evanoff
Matt Evanoff

Reputation: 966

Like this? $('h4').eq(0).on('click', function() { $('p').eq(2).hide(); });

Upvotes: 1

Related Questions