检查jQuery中是否存在元素如果元素是由.append()方法?$('elemId').length对我不管用。
3 回答

慕田峪9158850
TA贡献1794条经验 获得超7个赞
$('elemId').length
对我不管用。
#
$('#elemId').length---^
#
document.getElementById('id_here')
id

温温酱
TA贡献1752条经验 获得超4个赞
if( $('#selector').length ) // use this if you are using id to check{ // it exists} if( $('.selector').length ) // use this if you are using class to check{ // it exists}

当年话下
TA贡献1890条经验 获得超9个赞
if ($("#mydiv").length > 0){ // do something here}
添加回答
举报
0/150
提交
取消