「jQuery」指定要素が存在するかどうか判定する方法

2020年10月21日

構文
$(selector).length
jQueryコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$(function () {
$('#cft).on('submit', function (event) {
//class="layoutTable'が存在判定
if($('.layoutTable').length){
console.log('exits');
}else{
 console.log('not exist);
}
});
}
$(function () { $('#cft).on('submit', function (event) { //class="layoutTable'が存在判定 if($('.layoutTable').length){ console.log('exits'); }else{  console.log('not exist); } }); }
$(function () {
  $('#cft).on('submit', function (event) {
       //class="layoutTable'が存在判定
    if($('.layoutTable').length){ 
      console.log('exits');
    }else{
     console.log('not exist);
    }
  });
}

 

jQuery

Posted by arkgame