재우니의 블로그


http://jqapi.com/#p=on


Attach and trigger custom (non-browser) events.


trigger 를 custom event 에 추가하기 


<!DOCTYPE html>
<html>
<head>
  <style>
p { color:red; }
span { color:blue; }
</style>
  <script src="http://code.jquery.com/jquery-1.7rc2.js"></script>
</head>

<body>
  <p>Has an attached custom event.</p>
<button>Trigger custom event</button>
<span style="display:none;"></span>
<script>


$("p").on("myCustomEvent", function(e, myName, myValue){
  $(this).text(myName + ", hi there!");
  $("span").stop().css("opacity", 1)
    .text("myName = " + myName)
    .fadeIn(30).fadeOut(1000);
});

$("button").click(function () {
  $("p").trigger("myCustomEvent", [ "John" ]);
});


</script>

</body>
</html>