Created
July 8, 2014 02:05
-
-
Save KatagiriSo/d9c11150f98097debc4a to your computer and use it in GitHub Desktop.
JQuery on click event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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