Minecraft PC IP: play.cubecraft.net

DrHam

Forum Veteran
Sep 15, 2015
3,615
4,165
518
Kepler-452b
As this subforum is as dead as Henry VII, I’ve made a little code snippet showing how to append code to an exiting something with an id. The code depends on WASM and web-sys. I’ve also made a superhuman effort to let you know what’s going on


Code:
#[wasm_bindgen]
pub async fn append_html(id: String, htmlcontent: String){

     let window = web_sys::window().expect("Window not found"); //Find window, store it
     let document = window.document().expect("Document not found"); //Find where’s the document on the window, store it
     let body = document.body().expect("No body"); //Find where’s the body on the document, store it
     let div_to_append = document.get_element_by_id(&id).unwrap();    //Find our div

  div_to_append.set_inner_html(&htmlcontent); //set new content to our doc

div_to_append.append_child(&div_to_append); //spend the new content
You can then call the code (after having properly compiled and included necessary files/scripts) doing the following (on the HTML/php/whatever file)
Code:
wasm_bindgen.append_html(“id”, “Yes”)


I haven’t tested it (nor used an ide, only superior xenForo), so I’ve probably made a mistake somewhere. You get extra points if you find it
 
Last edited:
Members Online

Members online

Latest posts

Latest profile posts

UncleSpect wrote on xSchulzis's profile.
Hiiii xSchulzis! :D
UncleSpect wrote on Roxlad's profile.
Happy birthday! 🎈
UncleSpect wrote on WolfX's profile.
Happy birthday! 🎈
UncleSpect wrote on Ferrcho's profile.
Happy birthday! 🎈
Heya, after a good while years having not appreciated sleep a lot, have I learned things. I have most of the times seen it as a hindrance to things such as relations and projects. But after years I realised that you need to sleep to be well. Both physically and mentally. When I also realized that I could work better and more efficiently, did I try to get more sleep. That reminds me, I need to sleep now hah XD
Top Bottom