0

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

5
  • $(this).parent().prev().toggle(); also add jQuery library in JSBIN Commented Jun 16, 2016 at 5:02
  • jsbin.com/famoqofeya/1/edit?html,css,js,output Commented Jun 16, 2016 at 5:03
  • did you include j Query URL in you Page ` <script src="code.jquery.com/jquery-1.10.2.js"></script>` Commented Jun 16, 2016 at 5:17
  • @MohammadFareed ya i forgot to post it but still it doesnt work. Commented Jun 16, 2016 at 5:32
  • can you please tell me, what you need in your DEMO .? So that i can help you Commented Jun 16, 2016 at 5:40

4 Answers 4

2

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(); }); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you this is what i'm looking for
0

Lets make this simple

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

hope this will work for you

1 Comment

if there many box like that .. if i click the button , all will effect, i want the effect 1 by 1 , if i use your suggestion 1 click all parent div will got the same effect.
0

you can also do like this, it works.

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

Comments

0

.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(); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.