我在class fieldValidation的元素(下面用粗体表示)。并尝试导航到undefined method
内的标签字段。
这就是我正在做的事情。
.fTitleCell
fTitleCell和fInputCell的模式继续用于多个字段,对于每个fInputCell,我需要遍历最近的fTitleCell并获取其标签。
$(".fieldValidation").each(function(){
console.log($(this).prev("fTitleCell").text);
});
答案 0 :(得分:1)
你需要回到父母那里。然后到之前的兄弟元素,然后寻找标签。
JsFiddle as a working exemple.
$(".fieldValidation").each(function(){
console.log($(this).parents('.fInputCell').prev('.fTitleCell').find('label').text())
});
答案 1 :(得分:0)
$(".fieldValidation").each(function(){
var $parentRow = $(this).closest('.fRow');
var label = $parentRow.find('.fTitleCell label');
});