notForTYO
notForTYO

Reputation: 3

Simply function to separte buttons

I have very basic problem, actually it's look Here. I want to separate two buttons.

jQuery

$( "span" ).click(function() {
  $( "p" ).toggle( "slow" );
});

HTML

<span>↓ Hobby </span>
<p class="contentDiv" >Such interesting text, eh?</p>
    <br> <br>
 <span>↓ Sport </span>
<p class="contentDiv" >Such interesting text, eh?</p>

I was trying by getElementById but it doesn't work.

I'm beginner, be patient.

Upvotes: 0

Views: 50

Answers (2)

sudhansu63
sudhansu63

Reputation: 6180

Try this.

$( "span" ).click(function() {
  $(this).closest('p').toggle();
});

Upvotes: 0

Anton
Anton

Reputation: 32581

When you are using $('p') you are selecting all p elements, you need to specify like this

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

Upvotes: 2

Related Questions