简体   繁体   中英

advanced selector doesn't match using jquery

I have three ids in DOM, but somehow this code don't work? No error

$(function() {
  console.log('test')

  $('[div][id*="sohai"]').each(function() {
  console.log($(this))
})
})

https://jsbin.com/bumoyezena/edit?html,js,console,output

Remove [] surrounding the div selector

 $(function() { console.log('test') $('div[id*="sohai"]').each(function() { //^---^-------------------- console.log(this.id); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="sohai-1"></div> <div id="sohai-2"></div> <div id="sohai-3"></div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM