0

on my site i want to do a custom select. On click i want to slideDown a div, which have some filters. Structure:

<div class="select" style="position:relative;height:20px;">
   <span class="label">somelabel</span>
   <div style="display:none;position:absolute;top:20px;left:0;" class="select_inner">
      <label for="something">
         <input type="text" name="something">
      </label>
      <label for="something">
         <input type="text" name="something">
      </label>
   </div>
</div>

Div with class select_inner is hidden, i want to show it when somebody click on span width class label. And hide when somebody click on everything else except div with class select_inner. And thats the problem... I try something like this:

$('.select').click(function(){
   var select = $('.select_inner', this);
   select.slideDown();
   $(this).parents().click(function(){
      select.slideUp();
   });
});

And it works but wrong. When i click on my div, child div slides down and instantly up...

2 Answers 2

1

Try

$('.select span.label').click(function(){
    $('.select_inner').slideToggle("fast");
});
Sign up to request clarification or add additional context in comments.

Comments

0

You can do this:

$('.select').click(function(event){
event.stopPropagation();
var select = $('.select_inner', this);
select.slideDown();

});

$('html').click(function() {
 var select = $('.select_inner', this);
 select.slideUp();
});

​ ​ See this jsfiddle. The way it works is that on any click outside of the select div, it attempts to slide up the div, but if you click on the select div, it will stop the event and do a slideDown instead.

EDIT

I made a mistake in the initial script. I updated the script above to fix the problem. See the updated fiddle in IE and Firefox: http://jsfiddle.net/A6ZNY/1/

2 Comments

No problem. Don't forget to mark it as the correct answer by selecting the tick mark next to the answer.
See the updated script. I forgot to pass in the event in the function. This one will work in IE and Firefox

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.