【发布时间】:2013-08-30 10:40:00
【问题描述】:
我正在存储一系列这样的类:
var sectionParentID = $(this).parent('section').attr('class');
父级有多个类。例如,上述变量可能返回“section one titleAdded”或“section two titleAdded”或“section three titleAdded”
我关心的类是数字:一、二、三等。有了这些数字,我需要定位另一个具有相同类的 div(一、二、三等)
var sectionParentSelector = $(".product_totals").find(" ." + sectionParentID);
当我像这样记录选择器时:console.log(sectionParentSelector) 它返回以下不正确的选择器:
.product_totals .section two titleAdded
我需要它返回.product_totals .two
我可以做些什么来隔离这里需要的类?
【问题讨论】:
-
感兴趣的班级总是第二名?在这种情况下,您可以将其拆分并取第二个,例如 jsfiddle.net/IrvinDominin/c7Pax
标签: jquery jquery-selectors selector