选择<a>标记,其中<输入>与jQuery在一起
Select <a> tag where <input> is inside with jQuery
我需要将style="text-decoration: none;"
应用于包含<input>
标记的所有<a>
标记。由于我不能用CSS来做这件事,我想jQuery可以帮助我找到这个案例的位置,并应用样式。
示例:
<a href="http://www.google.com"><input type="button" value="Click here to go to Google!" /></a>
我知道.css('text-decoration', 'none')
应用CSS,但我该如何找到标签
您可以使用:has
选择器:
$("a:has(input)").css("text-decoration", "none");
或.has
方法:
$("a").has("input").css("text-decoration", "none");
演示
如果你只想要那些直接父母,你可以使用
$("input").parent("a");
如果你想要最近的祖先,你可以使用
$("input").closest("a");
如果你想要所有的祖先,你可以使用:
$("input").parents("a");
实现这一点(至少)有两种方法:
$('a').has('input').css('text-decoration', 'none');
$('a:has(input)').css('text-decoration', 'none');
$('a:has(input)')
或
$('input').parents('a')
相关文章:
- 正在检测导航到<a name=“;最新主题”></a>
- 如何附加<ul><李>元素位于某个特定条件的父元素列表之间
- 在<script src=“"></脚本>标签
- 等效于<script src=“;something1.json”></脚本>
- CSS/.JS问题,<ul><李>在Megamenu中
- 如何在<td></td>在Procractor中
- 显示“<script src='some.js'></脚本>"在Html文档中
- 如何将Array转换为<ul><李>以字母为标题的字母列表
- <script src=“//代码.jquery.com/jquery-1.11.1.min.js”></
- 选择<脚本></脚本>作为html正文中的纯文本
- 可折叠<UL><李>不起作用
- $.mobile.loadPage()和$(“linkBtn”).click();t负载<头部></头部&
- <脚本/>vs<脚本></脚本>webpack和angular
- Javascript/RRails-如何包装link_to而不是<a></a>在javascript
- jQuery在处理<选择><选项>
- 布局lt md已被弃用.请使用`layout gt-<xxx>`变种
- 在<%%中定义的访问变量>从<脚本></脚本>
- 页面设计<a href><按钮><输入>在JSP中
- 注入html标记<ul></ul>在我的<李></李>元素
- jQuery选择器<按钮></按钮>