Haxe js api was incomplete: js.html.Element has no field src

js.html.Element has no field src
var tag=document.createElement("script");

tag.src = "";//js work
import js.Browser;

class YoutubePlayer {
	public function new() {
		var tag = Browser.document.createElement('script');
		tag.src = "";//error here.

	public static function main() {
        var p=new YoutubePlayer();


Because js.html.Element does not have a src field. ScriptElement does.

Try that:

var tag:js.html.ScriptElement = cast js.Browser.document.createElement('script');
tag.src = ""; // works fine

Try that in js to see what you’re getting:

// HTMLScriptElement

oh…I see. thanks .

You can also use document.createScriptElement and simular methods instead of cast (exists only in Haxe api). Cast only required for getElement stuff.

1 Like