Skip to content

Instantly share code, notes, and snippets.

@KatagiriSo
Created July 8, 2014 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KatagiriSo/d9c11150f98097debc4a to your computer and use it in GitHub Desktop.
Save KatagiriSo/d9c11150f98097debc4a to your computer and use it in GitHub Desktop.
JQuery on click event
<html>
<head>
<title>Sample</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js">
</script>
<script type="text/javascript">
// 動的な要素にも利用できるようなイベント構文について説明
// onメソッドを使えば良い
// 調査範囲.on(イベント名, セレクタ, イベントで実行したい処理)
//
$(function(){
//クリックイベント設置
$("body").on("click","div", function(){
$("div").text("Click");
});
// 動的にdiv追加
$("<div>").appendTo("body");
});
</script>
<style>
<!--
div {
width:50px;
height:50px;
color:#fff;
background-color:#09c;
}
-->
</style>
</head>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment