jQuery - 选择器不断变化

jQuery - selector keeps changing

这是我的选择器的样子:

$("#testMyCard-123 > div.test1 > div.test3 > tr > h4");

一段时间内一切正常,但随后数字 123 变为 456。我的选择器停止工作,因为 $("#test-123... 变成 $("test-456...

一次包含的正确方法是什么,比如 $("#testMyCard-123...contains('testMyCard'...

您可以使用 attribute starts with 伪选择器,使用 id 作为属性:

$("[id^=testMyCard] > div.test1 > div.test3 > tr > h4");