最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Advanced selector - Hide Parent - Stack Overflow

programmeradmin1浏览0评论

Here is my HTML:

<td>
 <a class="button" href="#">
  <input id="download">...</input>
 </a>
 <a class="button" href="#">
  <input id="downloadcsv">...</input>
 </a>
</td>

Using CSS I want to hide the <a> which contains an input with the ID = downloadcsv

Is there a parent option in CSS?

Edit: As current aswers indicate you cant hide a parent element based on the class of one of its childeren.

Is it possible to do this simply in Javascript, rather than using a framework like jQuery?

Here is my HTML:

<td>
 <a class="button" href="#">
  <input id="download">...</input>
 </a>
 <a class="button" href="#">
  <input id="downloadcsv">...</input>
 </a>
</td>

Using CSS I want to hide the <a> which contains an input with the ID = downloadcsv

Is there a parent option in CSS?

Edit: As current aswers indicate you cant hide a parent element based on the class of one of its childeren.

Is it possible to do this simply in Javascript, rather than using a framework like jQuery?

Share Improve this question edited Jun 29, 2010 at 21:00 CLiown asked Jun 29, 2010 at 16:12 CLiownCLiown 13.9k50 gold badges127 silver badges205 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

Assuming the <a> is the direct parent of the downloadcsv-input, you can just use

document.getElementById("downloadcsv").parentNode.style.display = "none"

This is not possible with CSS (2). However, it is possible with jQuery.

To expand on Fran's answer, the jQuery solution would be this:

$("a:has(#downloadcsv)").hide();

Otherwise, you'll need to put a class on the parent <a> indicating that it is the parent of #downloadscv.

发布评论

评论列表(0)

  1. 暂无评论