Thursday, June 1, 2017

jQuery Event


   💥 All the different visitor's actions that a web page can respond to are called events.

  💥  An event represents the precise moment when something happens.
Examples:
  • moving a mouse over an element
            💧<script>
$(document).ready(function(){
    $("p").on({
        mouseenter: function(){
            $(this).css("background-color", "lightgray");
        }, 
        mouseleave: function(){
            $(this).css("background-color", "lightblue");
        },
        click: function(){
            $(this).css("background-color", "yellow");
        } 
    });
});
</script>

  • selecting a radio button
           💧<script>
$(document).ready(function(){
    $("input").keypress(function(){
        $(this).hide();
    });
});
</script>

  • clicking on an element

  •        💧<script>
    $(document).ready(function(){
        $("p").on("click", function(){
            $(this).hide();
        });
    });
    </script>

No comments:

Post a Comment