Change Survey HTML with JavaScript
SurveyJS Form Library offers multiple customization options for survey elements (panels and questions):
- Configure templates for answer options in single- and multi-select questions (View Demo)
- Implement custom question renderers based on built-in question types (View Demo)
- Create custom question types (View Demo)
If none of these options meets your requirements, you can handle events to modify HTML markup of individual survey elements. The SurveyModel
class raises the following events for this purpose:
onAfterRenderQuestion
onAfterRenderQuestionInput
onAfterRenderMatrixCell
onAfterRenderPanel
onAfterRenderPage
onAfterRenderSurvey
Each of these events accepts the options.htmlElement
parameter, which contains an HTMLElement
object. You can use its properties and methods to change HTML markup in your JavaScript code. For example, this demo shows how to add tooltips to question titles. Tooltip texts are specified in a question's title
property and are separated from the title text by a special character combination ("||"
). The onAfterRenderQuestion
event handler splits the title
property value and assigns title text to HTMLElement
's innerText
property and the tooltip text to HTMLElement
's title
property. Hover the mouse pointer over a question title to see its tooltip.