switch element | SVGSwitchElement object
Provides conditional processing based on the state of the requiredFeatures, requiredExtensions, and systemLanguage attributes.
![]() ![]() |
DOM Information
Inheritance Hierarchy
Members
The SVGSwitchElement object has these types of members:
Events
The SVGSwitchElement object has these events.
| Event | Description |
|---|---|
| onload |
Occurs when the browser has fully parsed the element and all of its descendants. |
Methods
The SVGSwitchElement object has these methods.
| Method | Description |
|---|---|
| getBBox |
Gets the bounding box, in current user space, of the geometry of all contained graphics elements. |
| getCTM |
Gets the transformation matrix that transforms from the current user units to the viewport coordinate system for the nearestViewportElement object. |
| getScreenCTM |
Gets the transformation matrix from the current user units to the screen coordinate system. |
| getTransformToElement |
Gets the transformation matrix that transforms from the user coordinate system on the current element to the user coordinate system on the specified target element. |
| hasExtension |
Determines if the specified extension is supported. |
Properties
The SVGSwitchElement object has these properties.
| Property | Description |
|---|---|
|
Gets the names of the classes that are assigned to this object. | |
|
Sets or retrieves a reference to the SVG graphical object that will be used as the clipping path. | |
|
Gets a value that indicates whether referenced resources that are not in the current document are required to correctly render a given element. | |
|
Gets a value that represents the farthest ancestor svg element. | |
|
Determines if an element can acquire keyboard focus (that is, receive keyboard events) and be a target for field-to-field navigation actions (such as when a user presses the Tab key). | |
|
Sets or retrieves a value that indicates a SVG mask. | |
|
Gets a value that indicates which element established the current viewport. | |
|
Gets the nearest ancestor svg element. | |
|
Gets a white space-delimited list of required language extensions. | |
|
Gets or sets a white space-delimited list of feature strings. | |
|
Gets a style object. | |
|
Gets or sets a comma-separated list of language names. | |
|
Gets the value of a transform attribute. | |
|
Gets the element that established the current viewport. | |
|
Gets or sets the | |
|
Gets or sets a value that specifies the language that is used in the contents and attribute values of an element. | |
|
Gets or sets a value that indicates whether white space is preserved in character data. |
Standards information
- Scalable Vector Graphics: Document Structure, Section 5.11.13
Remarks
The switch element evaluates the requiredFeatures, requiredExtensions, and systemLanguage attributes on its direct child elements in order, and then processes and renders the first child element that these attributes evaluate to TRUE for. All other child elements are skipped and not rendered. If the child element is a container element (such as an g element), the entire subtree is processed and rendered or skipped and not rendered.
The values of the display and visibility properties does not affect the switch element processing. In particular, if you set display to none on a child element of a switch element, it does not affect TRUE and FALSE testing that is associated with processing switch elements.
Examples
The following code example uses the switch element to provide a graphical representation of a paragraph if XMHTML is not supported.
<?xml version="1.0" standalone="yes"?> <svg width="4in" height="3in" version="1.1" xmlns = 'http://www.w3.org/2000/svg'> <!-- The <switch> element will process the first child element whose testing attributes evaluate to TRUE.--> <switch> <!-- Process the embedded XHTML if the requiredExtensions attribute evaluates to TRUE (that is, the browser supports XHTML embedded within SVG). --> <foreignObject width="100" height="50" requiredExtensions="http://example.com/SVGExtensions/EmbeddedXHTML"> <!-- XHTML content goes here --> <body xmlns="http://www.w3.org/1999/xhtml"> <p>Here is a paragraph that requires word wrap.</p> </body> </foreignObject> <!-- ELSE, process the following alternate SVG. Note that there are no testing attributes on the <text> element. If no testing attributes are provided, it is as if there were testing attributes and they evaluated to TRUE.--> <text font-size="10" font-family="Verdana"> <tspan x="10" y="10">Here is a paragraph that</tspan> <tspan x="10" y="20">requires word wrap.</tspan> </text> </switch> </svg>
See also

