0

I wanted to achieve the bottom part of this: (https://stackoverflow.com/a/11545559/688830), so that when my form is clicked it remains. But for me, it doesn't remain. Any idea why?

<script>
$(document).ready(function () {
    $("#pvauth").click(function () {
        $("#container_demo").show();
        $("#pvauth").hide();

    });
});
</script>      

// this script only half works.. it hides when i click on form but i want it to stay.                      

<script type="text/javascript">
$(document).click(function (e) {
    // check that your clicked element has no id=info
    if (e.target.id != 'container_demo' && !$('#container_demo').find(e.target).length && e.target.id != 'pvauth') {
        $("#container_demo").hide();
        $("#pvauth").show();
    }
});
</script>
Community
  • 1
  • 1
jsky
  • 2,225
  • 5
  • 38
  • 54
  • 1
    You need to look at [stoppropagation](http://stackoverflow.com/questions/5963669/whats-the-difference-between-event-stoppropagation-and-event-preventdefault) – mplungjan Aug 13 '13 at 04:50
  • thanks. i just tried adding that call with no success. but it sounds like the solution, once i understand it more. – jsky Aug 13 '13 at 06:13
  • where do i put the stopPropogation method? ive tried it in several configurations. please show me in an answer and i will accept your answer as the solution thanks. – jsky Aug 13 '13 at 06:34
  • what you wanna do...clicking form hide the div and clicking again on anywhere in form show that hidden div???? – maverickosama92 Aug 13 '13 at 06:35
  • no. atm i have the form container and a button. when i click the button it shows the form container and it hides the button. also when i click outside the form it hides the container and shows the button again. but however when i click into the input box or onto the container instead, it also hides the form and shows the button. so this last behavior is what im trying to prevent propogating, i want the form to stay, and button to stay hidden, but how to achieve this with stopPropogate? – jsky Aug 13 '13 at 06:42

1 Answers1

1

Try

$(function() {
  $("input").on("click",function(e) { 
   e.stopPropagation();
  });
});

Instead of "input" you can narrow it down to "#container_demo"

mplungjan
  • 169,008
  • 28
  • 173
  • 236