使用jQuery在另一个元素中按类名获取元素 [英] Get elements by class name inside another element with jQuery

查看:78
本文介绍了使用jQuery在另一个元素中按类名获取元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过id获取元素,然后在此元素中使用jQuery按类名获取所有元素?使用标准JS函数getElementById()和getElementsByClassName()很容易做到这一点,但遗憾的是IE 7-8不支持后者。

How can I get an element by id, and then inside this element get all elements by class name using jQuery? It's pretty easy to do this using the standard JS functions getElementById() and getElementsByClassName(), but unfortunately IE 7-8 do not support the latter.

推荐答案

你有几个选择:

第一个,使用css选择器:

The first, using a css selector:

$('#idOfElement .classNameOfElements');

或使用 find()

$('#idOfElement').find('.classNameOfElements');

或使用选择器上下文:

$('.classNameOfElements', '#idOfElement');

值得注意的是,使用上下文(final)方法会导致jQuery在内部实现 find()方法。

It's worth noting that using the context (final) approach causes jQuery to internally implement the find() method.

参考文献:

  • find().
  • selector context.

这篇关于使用jQuery在另一个元素中按类名获取元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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