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))
})
})
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.