0

使用 jQuery,是否有更短的方法来编写以下内容?

$(this).parent().prev().children('.expand-rss-link').css({border:'solid 1px pink'});

以下不起作用...

$(this).closest('.expand-rss-link').css({border:'solid 1px pink'});

不起作用。

我的 HTML 源代码如下所示...

<div class="career-paths">
  <div class="career-paths-head">
  <h3>Agribusiness</h3>
  <a href="#" class="expand-rss-link">View All</a>
  <hr>
  </div>
  <div id="agribusiness-intern" class="expand-rss-section">
   <p>content</p>
  </div>
</div>

$(this) 代表<p>content</p>面积。

感谢您的建议

4

3 回答 3

1

尝试类似的东西

$(this).closest('.career-paths').find('.expand-rss-link').css({border:'solid 1px pink'});
于 2013-08-21T16:10:53.243 回答
1
$(this).closest("parent level id in which '.expand-rss-link' come as children " here come ".career-paths" ).find('.expand-rss-link').css({border:'solid 1px pink'});

所以现在的代码是

$(this).closest(".career-paths").find('.expand-rss-link').css({border:'solid 1px pink'});
于 2013-08-21T16:09:39.553 回答
1

试试这个::

$(".expand-rss-link", $(this).closest('.career-paths')).css({border:'solid 1px pink'});

希望这会有所帮助!

于 2013-08-21T16:15:03.510 回答