web_sys::Document::set_body function

Example

This example creates a new body element, set the bgColor by dynamically casting it to HtmlBodyElement, and assign the created element to the document by calling set_body.


	pub fn document_set_body()
	{
		let window = web_sys::window().expect("global window does not exists");    
		let document = window.document().expect("expecting a document on window");
		let body = document.create_element("body").unwrap();
		let body_html_body_element = body
		.dyn_into::<web_sys::HtmlBodyElement>()
		.unwrap();
		body_html_body_element.set_bg_color("lightgreen");    
		let body_html_element = body_html_body_element
								.dyn_into::<web_sys::HtmlBodyElement>()
								.unwrap();
		document.set_body(Some(&body_html_element));
		
	}

Function


	pub fn set_body(&self, body: Option<&HtmlElement>)

features/dependencies

Source Code