web_sys::Document::get_element_by_id function

Example

This example demonstrates the get_element_by_id method of the document element. The method retrieves the "paragraphId" element and then log its inner text to the console.


	pub fn document_get_element_by_id()
	{
		let window = web_sys::window().expect("global window does not exists");    
		let document = window.document().expect("expecting a document on window");
		//let body = document.body().expect("document expect to have have a body");
		let val = document.get_element_by_id("paragraphId")
		.unwrap()
		.dyn_into::<web_sys::HtmlElement>()
		.unwrap();
		web_sys::console::log_2(&"URL: %s".into(),&JsValue::from_str(&val.inner_text()));
	}

Function


	pub fn get_element_by_id(&self, element_id: &str) -> Option<Element>

features/dependencies

Source Code