如何找到父母的先前兄弟姐妹 [英] How to find the previous sibling of parent
本文介绍了如何找到父母的先前兄弟姐妹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,我知道这应该很简单.我有一个定义列表(< dl>
),其中包含数据定义和数据标签.我在数据定义之一中有一个输入,因此用户可以定义该定义.
Okay, I know this should be simple. I have a definition list (<dl>
) that contains data definitions and data labels. I have an input in one of the data definitions so a user can define the definition.
然后,我试图获取该定义的标签名称.在演示中,警报应以"cycle_3"提示.
I am then trying to get the name of the label for that definition. In the demo the alert should prompt with "cycle_3".
var myErrors = $('.myTest').prev('dt').text();
console.log(myErrors);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<dl>
<dt> cycle_1:</dt>
<dd> test </dd>
<dt> cycle_2: </dt>
<dd> test </dd>
<dt> cycle_3: </dt>
<dd>
<input class="myTest" value="test" />
</dd>
</dl>
推荐答案
$('.myTest').parent().prev('dt').text();
这篇关于如何找到父母的先前兄弟姐妹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文