如何减少我在jQuery函数中使用的子代数量? [英] How can I reduce the amount of children I use in my jQuery functions?

查看:105
本文介绍了如何减少我在jQuery函数中使用的子代数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得我必须在某些jQuery函数中使用太多的.children().

I feel like I have to use way too many .children() in some of my jQuery functions.

这是我的HTML:

<div class="goal-small-container">
  <div class="goal-content">
    <div class="goal-row">
      <span class="goal-actions">

这是我的jQuery:

And here's my jQuery:

$('.goal-small-container').hover(function() {
  $(this).children('.goal-content').children('.goal-row').children('.goal-actions').css({visibility: "visible"});
}, function () {
  $(this).children('.goal-content').children('.goal-row').children('.goal-actions').css({visibility: "hidden"});
});

有没有更好的方法?如何减少我在jQuery函数中使用的子代数量?

Is there a better way? How can I reduce the amount of children I use in my jQuery functions?

推荐答案

.find('.goal-content .goal-row .goal-action').whatever()

或更简单地说:

.find('.goal-action').whatever()

这篇关于如何减少我在jQuery函数中使用的子代数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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