有相对的jQuery选择器之类的东西吗? [英] Is there such thing as a relative jQuery selector?

查看:101
本文介绍了有相对的jQuery选择器之类的东西吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用this变量引用了一个jquery对象.我正在寻找一种将子选择器应用于对象的方法.

I have a reference to a jquery object with the this variable. I am looking for a way of applying the child selector to the object.

我正在使用$(this).find('table > tbody > tr > td'),但我的目标是更像$('[Value of $(this) goes here somehow] > table > tbody > tr > td').

I'm using $(this).find('table > tbody > tr > td'), but what I'm aiming for is something more like $('[Value of $(this) goes here somehow] > table > tbody > tr > td').

我意识到我可以做到$(this).children('table').children('tbody').children('tr').children('td'),但是我想知道这里是否可以使用一些语法糖.

I realise that I can do $(this).children('table').children('tbody').children('tr').children('td'), but I was wondering if there was some syntactic sugar I could use here.

推荐答案

您可以从子选择器开始(>),同时使用 .find() 时,就像这样:

$(this).find('> table > tbody > tr > td')

这是一个经常被忽视的用例,但是对于您所追求的东西来说却非常有用.

It's an often overlooked use case, but it works just great for what you're after.

这篇关于有相对的jQuery选择器之类的东西吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆