select 元素如何使用 jquery 以特定文本开始和结束?

How to select element has id start and end with specific text using jquery?

我有多个 div,其 ID 类似于 course1_popupcourse2_popupcourse3_popup。我想做一个类似

的函数
$('#course*_popup').hide();

以便所有 course*_popup div 都应该隐藏,但这不起作用。有什么想法吗?

使用属性 starts with and ends with 选择器的组合。

$('[id^="course"][id$="_popup"]').hide();

仅供参考: 对此类元素组使用通用 class 会好得多。

最简单的方法:给所有相同的 class,例如 course_popup,然后:

$('.course_popup').hide()

其他解决方案是在几秒钟前发布的;)