Reputation: 891
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
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.
Upvotes: 1
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
Reputation: 966
Like this? $('h4').eq(0).on('click', function() { $('p').eq(2).hide(); });
Upvotes: 1