如何选择一个DOM元素的动态元素? (css选择器) [英] How to select a dinamic following DOM element of a DOM element? (css selector)

查看:206
本文介绍了如何选择一个DOM元素的动态元素? (css选择器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

html:

<div>Hello</div
<my-custom-el>content</my-custom-el>

< my-custom-el> 可以是< my-custom-el> ,其他时间< his-custom-el> 等等...

The <my-custom-el> can be once <my-custom-el>, other time <his-custom-el> etc...

有没有办法让css选择< div> 之后的元素,而不知道是什么DOM元素类型将会是什么?

Is there a way to css select the element after the <div>, without knowing what DOM element type will be?

推荐答案

是的,与相邻兄弟(邻居)选择器 + 和通用选择器 *

Yeah, with the combination of adjacent sibling ("neighbor") selector + and universal selector *:

div + * { }

这将选择任何 >立即跟随DOM中的任何 div 元素,其中立即表示这两个元素必须具有相同的父元素。

This will select any element that immediately follows any div element in the DOM, where immediately means that both elements must have the same parent element.

小提琴

这篇关于如何选择一个DOM元素的动态元素? (css选择器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆