-
Notifications
You must be signed in to change notification settings - Fork 4
/
jquery.html.erb
68 lines (51 loc) · 1.58 KB
/
jquery.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<h1>Play jQuery</h1>
<input id="input-text" type="text">
<input id="input-submit" type="submit">
<ul id="foo">
<li data-color="red">AAA
<a href="#" class="remove">Remove</a>
<a href="#" class="update-author">Update author</a>
<span class="author">111</span>
</li>
<li data-color="blue">BBB <a href="#" class="remove">Remove</a></li>
<li data-color="green">CCC <a href="#" class="remove">Remove</a></li>
</ul>
<a href="#" id="insert-data">Insert Data</a>
<a href="#" id="toggle-list">Toggle List</a>
<a href="https://ihower.tw" id="get-link">ihower</a>
<script>
$("li").mouseover(function(){
var color = $(this).data("color");
$(this).css( { background: color } )
})
$("#input-submit").click(function(){
var it = $("#input-text")
var str = it.val();
$("#foo").prepend("<li>" + str + "</li>")
it.val("");
})
$("#get-link").click(function(event){
event.preventDefault()
console.log( $(this).attr("href") );
})
$("#foo .update-author").click(function(){
var update = $(this);
var li = update.closest("li");
var author = li.find(".author");
author.html("Q___Q");
})
// $("#foo .remove").click(function(event){
$("#foo").on("click", ".remove", function(event){
event.preventDefault()
var remove = $(this);
var li = remove.closest("li");
li.remove();
})
// $("#insert-data").click(function(){
$("#insert-data").on("click", function(){
$("#foo").append('<li>DDDD <a href="#" class="remove">Remove</a></li>')
})
$("#toggle-list").click(function(){
$("#foo").slideToggle();
})
</script>