所以我可以找到一個元素是否是父元素的子元素,但我無法弄清楚如何獲取父元素中當前元素的索引。例如。我在我的頁面上摺疊了文章http://gundlach-marketing.com/dev,爲了重置頁邊距,我需要知道它們是什麼文章編號。找到父元素jquery的哪個子元素
var articleId = $(this).attr('id');
var articleIndex;
$(this).parent().children('article').each(function (index) {
if ($(this).attr('id') == articleId) {articleIndex = index}
});
上面的代碼工作,它只是不雅觀。一定有更好的方法!它是什麼?
相關:http://stackoverflow.com/questions/2342376/how-to-find-position-number-of-a-specific-child-element-in-a-parent-element-using?rq = 1 – megawac