[SOLVED] Creating new elements in a new document | Sololearn: Learn to code for FREE!

+4

[SOLVED] Creating new elements in a new document

I open a new document in html by clicking on a specific element . For exp : <div class="g"></div> In js : $('.g').click(function (){ let doc =document; doc.open(); }) Ok so I'm gonna add new elements in this document, how can i do it ? I'm gonna add images , divs , paragraphs and also style them like in the main html document.

4/28/2021 6:02:40 PM

Farnaz.A

10 Answers

New Answer

+3

Farnaz.A It is possible. Just don't use append function. Use document.write See I have edited code again.

+3

Farnaz.A appendChild is a function of JavaScript not jQuery. There is append function in jQuery.

+3

🅰🅹 🅐🅝🅐🅝🅣 uhh just like I guessed . Thank u so much I appreciate ur help ✋

+2

Farnaz.A Use document.createElement() function to create new element and use appendChild() function to append that created element in any node element like body.

+2

Farnaz.A No need to open document. You can directly use document. You can create like this https://code.sololearn.com/WzmooAA4Fnq2/?ref=app

+2

Farnaz.A I just commented this line doc.open() and used append function https://code.sololearn.com/WNdpNdNHat0J/?ref=app

+1

🅰🅹 🅐🅝🅐🅝🅣 I did that but it didn't work . Can u please give me an example ? Use the code I've mentioned above tnx

+1

🅰🅹 🅐🅝🅐🅝🅣 https://code.sololearn.com/WnQXwKC9IQcc/?ref=app Line 173:$(...).appendChild() is not a function . Why ???!! i also tried it in document.getElementByClassName('gallery).appendChild(img1);

+1

🅰🅹 🅐🅝🅐🅝🅣 funny thing is I tried that also and it didn't work

+1

🅰🅹 🅐🅝🅐🅝🅣 but I want it to open in a new document.ain't that possible?