2

Can anyone help me? I'm trying to hide the #hideme div when the a user clicks the drop down menu (to select something) or puts the focus on the text field. Thanks!

   #hideme {
     background:#ccc;
    }

    <script>
    $(function(){
       $('#skill_select').click(function(){
            $('#hideme').hide();
        });
    }):
    </script>
    <select>
            <option selected="selected">Pick from the list</option>
            <option>Option One</option>
            <option>Option Two</option>
    </select>
    or <input type="text" value="type something">
    <br/><br/>
    <div id="hideme">Hide Me Please</div>
0

2 Answers 2

2

Give the select and textbox ID's:

<select id="mySelect">
    <option selected="selected">Pick from the list</option>
    <option>Option One</option>
    <option>Option Two</option>
</select>
or <input type="text" value="type something" id="myText">
<script type="text/javascript">
    function hideMe() {
        $('#hideme').hide();
    }

    $('#mySelect').change(hideMe);
    $('#myText').focus(hideMe);
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

@webwrks Remove the "double colon" at the end of your code (posted before in the comments). see jsfiddle.net/Pc5Pz
1

Assuming all you want to do is hide.

$('select, input').click(function() {
        $('#hideme').hide();
    });

If you want to show the div back again when user clicked outside select or input, then do this

$('select,input').click(function(e) {
    e.stopPropagation();
    $('#hideme').hide();
});
$(document).click(function() {
    $('#hideme').show();
})

Check working example at http://jsfiddle.net/2p6Y7/2/

Don't use select, input. Create id's for each of them and select them by there id.

1 Comment

This works Hussein, but I was trying to do it on focus and change like the Scrum Meister did it...why is The Scrum's not working?

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.