Find dynamic classname of element with jQuery
问题 I'm having a unknown number of elements like so: <div class="item item-1"></div> <div class="item item-2"></div> <div class="item item-3"></div> What I want to do, is check if each item has a classname starting with "item-". If true, then extract the id. Something like this: $("container").each(function if ($(this).hasClassNameStartingWith("item-")) console.debug(theId); ); How is this possible? Thanks in advance! 回答1: Use the contains selector on the class attribute: $('container[class*="