Scripts

This page introduces WSphynxJS scripts


Here, you are going to learn how to:


Add a script for a specific div

Script tag

You just have to add a wsscript tag inside a wsdiv:

<wsdiv> Vulnerant omnes, ultima necat <wsscript> </wsscript> </wsdiv>

Use regular JS:

Then, you can use regular JS inside the script tag:

<wsdiv> Nam et ipsa scientia potestas est <wsscript> console.log ("Ad gloriam"); </wsscript> </wsdiv>

Access to the div

It is possible to access to the div's methods through the element object. The element object refers to the wsdiv (or everything else see the Generalization chapter) which contains the wsscript.

Element object

The element object contains all native HTML methods and properties. You can, for example, get the innerHTML or classList properties.

<wsdiv> Consuetudo est optima legum interpres <wsscript> element.changeTextContent ("This text has been changed."); element.style.fontSize = "xx-large"; </wsscript> </wsdiv>

The script runs when the div has been fully loaded.

NOTICE: for some browsers, use the .textContent propertie may generate bugs. To avoid these bugs, use the .changeTextContent(text) method.

Copyright 2019 SphynxTech