$('elemId').length
doesn't work for me.
($('elemId').length
对我不起作用。)
You need to put #
before element id:
(您需要将#
放在元素ID之前:)
$('#elemId').length
---^
With vanilla JavaScript, you don't need the hash ( #
) eg document.getElementById('id_here')
, however when using jQuery, you do need to put hash to target elements based on id
just like CSS.
(使用香草JavaScript时,您不需要哈希( #
),例如document.getElementById('id_here')
,但是在使用jQuery时,您确实需要像CSS一样基于id
将哈希放入目标元素。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…