How can I remove events with off and reset them?

0

Good afternoon friends of stackoverflow, I would like to know how I can use the function off to remove some events click example: $("selector").off("click") my doubt remains on how I can revert these changes because I do not use it with on () .

Thank you.

    
asked by Tysaic 19.03.2018 в 19:46
source

1 answer

0

Example: Removing click event from all elements

I hope it helps you.

W3Schools Documentation

$(document).ready(function() {
  $("p").on("click", function() {
    $(this).css("background-color", "pink");
  });
  $("button").click(function() {
    $("p").off("click");
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<p>Click en este parrafo para cambiar de color.</p>
<p>Haga clic en el botón de abajo y luego haga clic en este párrafo (se elimina el evento click).</p>

<button>Remover evento click</button>
    
answered by 19.03.2018 в 19:53