---
title: "搜索上级dom对象并隐藏，点击隐藏父元素"
author: "夜鸣猪"
date: "2011-05-21T02:33:56Z"
tags: ["Java", "Ruby", "UP"]
categories: ["Web前端"]
slug: "dom"
draft: false
lastmod: "2011-05-21T02:33:56Z"
id: 1052405
url: "https://hlee.iteye.com/blog/1052405"
---

类似页面如下： \[code="java"]

text to hide 1

text to hide 2

\[/code] \[code="java"]$("input.chk").click(function(){ $(this).parent().parent().(".disabled").show(); }) ;\[/code] 实际使用.closest() 和 .find()更合适 \[code="java"]$("input.chk").click(function(){ $(this).closest('tr').find(".disabled").show(); });\[/code] 当然也可以 \[code="java"]$(this).parent().parent().find(".disabled").show();\[/code] 如果，有多行的话用.delegate()如下： \[code="java"]$("table").delegate("input.chk", "click", function(){ $(this).closest('tr').find(".disabled").show(); });\[/code] \[code="ruby"] #.delegate() instead binds one handler to the table for all of the input.chk elements to bubble up to. If you're looking to enable/disable, use hcnage and .toggle() in addition to the above, like this: $("table").delegate("input.chk", "change", function(){ $(this).closest('tr').find(".disabled").toggle(this.checked); });\[/code]