[英]How do I access direct descendants of a jquery object cleanly?
I have the following line in my js 我的js中有以下行
var description = jqref.children('.category_info').children('.description').children('p').html();
which works exactly how I want it, though to me it feels way too clunky which feels like I am overlooking a better selector method. 这完全符合我的要求,但是对我来说感觉太笨拙了,好像我正在忽略更好的选择器方法。
I'm fairly certain I ought to be using the >
direct child symbol but can't seem to implement it in the normal way as I am already dealing with a jquery object. 我相当确定我应该使用
>
直接子符号,但是由于我已经在处理jquery对象,因此似乎无法以常规方式实现它。
Use find with the child selector . 将find与子选择器一起使用 。 I learned something new;
我学到新东西; you can prepend the selector with a child selector to make sure that you only get children:
您可以在选择器之前添加子选择器,以确保仅获得子选择器:
var description = jqref.find('> .category_info > .description > p').html();
JSFiddle: http://jsfiddle.net/5SktL/ JSFiddle: http : //jsfiddle.net/5SktL/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.