Fiido93
Fiido93

Reputation: 1978

Hide and show Jquery

I think i have done a right thing, I click the button and the paragraph doesn't appear. Can anyone help me why with my jQuery?

$('.open').on('click',function(event){
  $(this).nextAll('.ranch').toggle();
});

DEMO

Upvotes: 0

Views: 88

Answers (4)

JackHasaKeyboard
JackHasaKeyboard

Reputation: 1665

.open is nested in another element, .nextAll() looks for siblings. You'll have to go one level further backwards for that to work.

Here's how I'd find the parent .content, that's just me though:

$('.open').on('click', function(event) {
  $(this).closest('.content').find('.ranch').toggle();
});

Upvotes: 0

VijayGupta
VijayGupta

Reputation: 675

you can also do like this, it works.

$(document).ready(function(){
    $('.open').on('click',function(){
 $('p.ranch').toggle();
 });

Upvotes: 0

Hk01
Hk01

Reputation: 70

Lets make this simple

$('.open').on('click',function(){
   $('p.ranch').toggle();
});

hope this will work for you

Upvotes: 0

SESN
SESN

Reputation: 1283

There is no jquery plugin attached in your html. Please check console for error.

http://codepen.io/SESN/pen/WxxZOg

Here is your answer

 $('.open').on('click',function(){
 $(this).closest('.content').find('p.ranch').toggle();
 });

Upvotes: 2

Related Questions