jQuery

cheat sheet



jQuery使html/css/js
libraryjQuery
jQueryhtml/css




$(function(){...})
HTML
DOMHTML
#??
DOM




list
id使class
2
loop
const $container = $('.container');
$container.each(function(index) {
$container.eq(index).f(...);
})
...
$(this).closet('.hoge-container').f(...);
...
twig
id="hoge-{{user.id}}"
$("#hoge-{{user.id}}").click(function ..)


clickblock
li
div.parent
span.price
button.submit click
li
button.submitspan.price
parent
spanbutton



text/val/html
text()
<b>a</b> <b>a</b>
val()
value使
input
.value() method
html()
dom
<b>a</b> a
innerText()
innerHtml()
value
textContent
a
jQuery JavaScript
.html("") .innerHTML = ""
.text("") .textContent = ""
.val("") .value = ""
.html() .innerHTML
.text() .textContent
.val() .value


find



data() attr() 使

mapelemthis
elem
this
$(this)
$(elem)
$.find('.hoge_list').map(function(elem){
elem.value ?
this.value ?
})
$()
$(document)

$
jQuery Objectprefix$
map
.map(function($elem, index) {...})
mrsekut
.map(function(e,i) { $elem = $(e)})


chain


delay()
.delay( duration [, queueName] )
delay()
#??
domcss
queue()
.queue( [queueName] )
$('#hoge').html('hoge').delay(3000).hide();
delay()
#hoge 'hoge' 3s
$('#hoge').html('hoge').delay(3000).queue(function() {
$(this).html('')
})
$(`#hogehoge`)
.text('hoge')
.stop(false, false)
.fadeIn()
.delay(1500)
.fadeOut();


Jesttest