简体   繁体   English

使用jQuery选择器在页面上找到元素

[英]Locate elements on the page using jQuery selector

I am currently using (eg) this in the console 我目前正在控制台中使用(例如)

> $("input[type='text']").css("background", "purple")

to highlight matched elements. 突出显示匹配的元素。 However, this doesn't work well when those elements are hidden. 但是,当这些元素被隐藏时,这不能很好地工作。 Is there a good way of doing it? 有一个好的方法吗?

EDIT: TO CLARIFY , I am only using the input tag as an example, and when I mean hidden I am talking about an element where it could be outside of the window, inside a hidden container, height 0, or whatever hard to find. 编辑:明确地说 ,我仅以input标签为例,当我的意思是隐藏时,我所谈论的是一个元素,该元素可能在窗口外,隐藏容器内,高度为0或任何难以找到的地方。 Generally not visible basically, not just display: none; 通常基本上不可见,而不仅仅是display: none; .

My concern is to locate all the matched elements for development purposes. 我关心的是找到所有匹配的元素以用于开发目的。 This question is not about how to make something purple! 这个问题不是关于如何使紫色变成东西!

可能是这样的:

$("input[type='text'], input[type='hidden']").css("background", "purple")

You could show the hidden elements before trying to change the background. 您可以在尝试更改背景之前显示隐藏的元素。

$("input[type='text']").show();
$("input[type='text']").css("background", "purple")

If the parent is hidden, show the parent first, then change the background color. 如果父对象是隐藏的,请先显示父对象,然后更改背景颜色。

$("input[type='text']").parent().show();
$("input[type='text']").css("background", "purple")

This should work: 这应该工作:

$("input[type='text'], input[type='text']:hidden").
    show().
    css("background", "purple");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM