MyInternships.in

HTML5 MathML

HTML5 MathML selection Attribute

The selection attribute on the <maction> element is a 1-based index that chooses which child expression is currently visible. Combined with actiontype="toggle", it records the state as the user clicks through children.


Definition and Usage

When <maction> has several children, selection says which one to show - 1 for the first, 2 for the second, and so on. For a toggle action the browser updates it on each click; for a static display it simply picks which child renders.

Syntax

Choosing the second child
Example
<maction actiontype="toggle" selection="2">
  <mn>1</mn>
  <mn>2</mn>
</maction>

Example

Displaying a chosen child
Example
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>MathML selection attribute</title>
</head>
<body>
  <math display="block">
    <maction actiontype="toggle" selection="2">
      <mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow>
      <mrow><mi>b</mi><mo>+</mo><mi>a</mi></mrow>
    </maction>
  </math>
</body>
</html>
⚠️

Because <maction> is not in MathML Core, browsers typically render only the child named by selection and ignore the interactive toggle. It still serves as a way to pick one static child.

Key Takeaways

  • selection is a 1-based index of the visible child in <maction>.
  • toggle updates it on each click where supported.
  • Most browsers just render the selected child statically.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships