3

i want one .heading click .collpase is active , remove and slideup and slide down but all collpase active how use jquery... i am tired , how use one click and one class active

$(document).ready(function(){
    $('.wrapmenu .heading').on('click', function(){
        $('.wrapmenu .collpase').addClass('acitve');
    });
});

///html

   <div class="heading">Transmission <span><i class="icon-caret-down"></i></div>
   <div class="collapse">
      <div class="checkbox"><label><input type="checkbox"> Automatic <span>(10)</span> </label></div>
     <div class="more-option">Show More Options <span><i class="icon-plus-sign"></i></span></div>
  </div>
</div>
    <div class="wrapmenu unicode ieUnicode">

   <div class="heading">Transmission <span><i class="icon-caret-down"></i></div>
   <div class="collapse">
      <div class="checkbox"><label><input type="checkbox"> Automatic <span>(10)</span> </label></div>
     <div class="more-option">Show More Options <span><i class="icon-plus-sign"></i></span></div>
  </div>
</div>

///css

.wrapmenu {
border:1px solid #ddd;
border-bottom:1px solid #ffffff;
cursor:pointer;
}
.wrapmenu .heading {
background-color:#F5F5F5;
padding:10px;
position:relative;
}
.wrapmenu .heading  span{
float:right;
}
.wrapmenu .collapse{
background-color:#fff;
padding:10px;
border-top:1px solid #ddd;
}
.active{display:block;}
2
  • You have a typo acitve Commented Jun 19, 2014 at 5:26
  • i wnat addClass and removeClass after SlideDown and SlideUp Commented Jun 19, 2014 at 5:39

3 Answers 3

3

Try to use the $(this) reference inside the click event handler, and target the element with class collapse by using the .next() function, since it is the immediately next sibling to the current element

$(document).ready(function(){
    $('.wrapmenu .heading').on('click', function(){
        $(this).next('.collapse').addClass('active');
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

how use slidedown solowly speed collpase class
1

Use this :

Here $(this) will gives you current clicked element and .next('.collpase') give you the next element which has class=collpase.

$(document).ready(function(){
    $('.wrapmenu .heading').on('click', function(){
        $(this).next('.collpase').addClass('acitve');
    });
});

Note : your active class spelling should be corrected.

Comments

1

Your selector is getting all the classes .collapse

For specific class

$(document).ready(function(){
    $('.wrapmenu .heading').on('click', function(){
        $(this).siblings('.collapse').toggleClass('active').slideToggle(1000);


    });
});

siblings(), here, would work if you have only one class .collapse.

If you have many .collapse in the same parent, use .next() as suggested by Rajaprabhu.

3 Comments

tanks my friends but i up vote not work up vote. i have no marks 15marks. so i not give up vote sorry....
how use slidedown and slideup myfriends
you cant, you need 15+ reputation to Vote up

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.