logo

G

  • Tutorials
  • API
  • Examples
  • Plugins
  • Productsantv logo arrow
  • 6.1.26
  • Introduction to the plug-in system
  • 插件结构
  • g-plugin-a11y
  • g-plugin-annotation
  • g-plugin-box2d
  • g-plugin-gpgpu
  • g-plugin-matterjs
  • g-plugin-yoga
  • g-plugin-css-select
  • g-plugin-3d
  • g-plugin-device-renderer
  • g-plugin-canvas-renderer
  • g-plugin-canvaskit-renderer
  • g-plugin-rough-canvas-renderer
  • g-plugin-rough-svg-renderer
  • g-plugin-canvas-path-generator
  • g-plugin-canvas-picker
  • g-plugin-svg-renderer
  • g-plugin-svg-picker
  • g-plugin-dom-interaction
  • g-plugin-dragndrop
  • g-plugin-control

g-plugin-css-select

Previous
g-plugin-yoga
Next
g-plugin-3d

Resource

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

When finding nodes in the scene graph, we can use some advanced query methods similar to the DOM API.

  • getElementById Find a single element by id in the subtree of the current node
  • getElementsByName Find a list of elements by name in the subtree of the current node
  • getElementsByClassName Find a list of elements by className under the subtree of the current node
  • getElementsByTagName Find a list of elements by tagName under the subtree of the current node

Suppose we construct the following scenegraph.

solarSystem<Group>
| |
| sun<Circle name='sun' />
|
earthOrbit<Group>
| |
| earth<Circle>
|
moonOrbit<Group>
|
moon<Circle r='25' />

We can use the following query methods.

solarSystem.getElementsByName('sun');
// [sun]
solarSystem.getElementsByTagName('circle');
solarSystem.getElementsByTagName(Shape.CIRCLE);
// [sun, earth, moon]

When we want to use more complex query criteria like CSS selectors, we have the option to install the plugin.

  • querySelector
  • querySelectorAll

Once the installation is complete the attribute selector can be used.

solarSystem.querySelector('[name=sun]');
// sun
solarSystem.querySelectorAll('[r=25]');
// [moon]

Usage

Create plug-ins and register them in the renderer.

import { Plugin } from '@antv/g-plugin-css-select';
webglRenderer.registerPlugin(new Plugin());

We can use something like the DOM API + CSS selector for node queries in the scene graph, full example.

solarSystem.getElementsByName('sun');
// [sun]
solarSystem.getElementsByTagName('circle');
solarSystem.getElementsByTagName(Shape.CIRCLE);
// [sun, earth, moon]
solarSystem.querySelector('[name=sun]');
// sun
solarSystem.querySelectorAll('[r=25]');
// [moon]