简体   繁体   English

如何链接javascript选择器

[英]how to chain javascript selectors

i've selected the following Ids in angularjs and i want to set the css to diplay none. 我在angularjs中选择了以下ID,并且我想将CSS设置为不显示。 the following code works well 以下代码效果很好

angular.element(document.getElementById('cont_' + i)).css({display: 'none' })
angular.element(document.getElementById('resize_' + i)).css({ display: 'none' })

is there a way to chain both selectors to i don't have to write 有没有办法将两个选择器都链接到我不必写

.css({display: 'none' })

twice? 两次? i tried the following but it obviously does not work 我尝试了以下方法,但显然不起作用

angular.element(document.getElementById('cont_' + i)).
angular.element(document.getElementById('resize_' + i)).css({ display: 'none' })

also, i need them to be with separate id because i use them individually in other places. 另外,我需要它们具有单独的ID,因为我在其他地方分别使用它们。

any ideas, 有任何想法吗,

thanx, 感谢名单,

您可以使用document.querySelectorAll,因此:

angular.element(document.querySelectorAll('#cont_' + i, '#resize_' + i)).css({display: 'none' })

Use css dynamic selectors. 使用CSS动态选择器。 Just get a parent element and then write div[id^=cont_] and write css there. 只需获取一个父元素,然后编写div[id^=cont_]并在其中写入CSS。

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

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