Fondations des WC - Shadow DOM

Dans cette article, nous allons nous intéresser aux fondations des composants web. Cela permettra de comprendre à la fois leur raison d’être et aussi comment ils sont construits.

Nous utiliserons des exemples simples et n'utiliserons pas de polyfill. Pour tester les bouts de code de cet article, le navigateur Google Chrome est le plus approprié.

Pour rappel, les spécifications des Web Components concernent :

  1. Les Templates : Permettent la réutilisation de fragments de code à l'aide de la balise <template>
  2. Le Shadow DOM : Permet l'encapsulation de sous-arbres DOM dans un élément hôte donnée.
  3. Les Custom Elements : Permettent la création et l'enregistrement de nouveaux éléments HTML
  4. Les Imports : Permettent l'importation de contenus dans un document HTML

Le Shadow DOM

C'est quoi au fait ?

Le Shadow DOM est une hiérarchie d'éléments HTML encapsulée dans un élément HTML dit élément hôte. Cette hiérarchie n'est pas accessible au document abritant l'élément. Ce concept est utilisé dans l'implémentation des balise natives HTML. l'exemple le plus parlant est la balise <video>.

Pour voir le Shadow DOM dans Google Chrome, il faut ouvrir DevTools, aller dans paramètres puis activer Show user agent shadow DOM

On voit bien que l'élément <video> est construit à partir d'autres éléments HTML standards. Tous ces éléments sont encapsulés et sont inaccessibles à partir du document.

Comment ajouter un Shadow DOM à un élément hôte ?

On considère le code HTML suivant :


  1. <h1>Ajout dans le shadow DOM</h1>
  2. <div id="hote"></div>

Nous allons ajouter dans la balise hôte une balise h2


  1. // Création d'un élément h2
  2. var h2 = document.createElement('h2');
  3. h2.textContent = 'Je suis dans le Shadow DOM';
  4. // Récupération de la référence de l'élément hôte
  5. var hote = document.querySelector('#hote');
  6. // Création du Shadow DOM
  7. var shadow = hote.createShadowRoot();
  8. // insertion de l'élément h2 dans le shadow dom
  9. shadow.appendChild(h2);

Si on ajoute a la page la feuille de styles CSS suivante, la déclaration n'affectera pas la balise se trouvant dans le Shadow DOM.


  1. h2 {
  2.     color: orangered;
  3. }

Et si on exécute l'instruction javascript document.querySelectorAll('h2'), la collection retournée sera vide.

Résultat :


Le Shadow DOM permet d'encapsuler un sous-arbre DOM dans un élément HMTL. Ni les styles ni les scripts Javascript n’affecteront pas les éléments de ce sous-arbre. Cependant, il existe des moyens pour percer cette coquille et accéder à l'intérieur de l'élément, à la fois avec les styles CSS et les scripts Javascript.


It is four Km from travels for kodaikanal Bus Stand.

CMS to create amazinjg free hosted websites.

Here is my blog Bonus Web design template (

If you desire to grow your know-how simply keep visiting this web site and be updated with the newest gossip posted Click Here.

I'm not sure why but this blog is loading very slow for me.

Is anyone else having this issue or is it a problem on my end?

I'll check back later and see if the problem still exists.

Have a look at my web blog :: cheap team football kits

Wonderful web site. A lot of helpful information here.

I'm sending it to a few friends ans also sharing in delicious.

And certainly, thank you on your effort!

my website: Social Warfare

Undeniably believe that which you stated.

Your favorite justification seemed to be on the internet

the simplest thing to be aware of. I say to you, I definitely get irked while people think about worries

that they just don't know about. You managed to hit the nail upon the

top and also defined out the whole thing without having

side effect , people can take a signal. Will likely be back to get more.


my homepage - escorts melbourne (

Colaterales De La Aorta Esophagus Trachea Anatomy Gonorrhea Treatment Dosage Ciprodex Otic Suspension Alcoholics Anonymous Prayers Pdf To Word Pinworms In Dogs Cure Stuffiness In One Nostril Astuce Pour Grossir Rapidement Synonyme Enthousiasme . What Virus Is Bell's Palsy Contagious Band Missouri Movin Amoxibiotic no prior prescription Buy Azibiot Overnight Online Narcolepsy And Driving Privileges Suspended Indefinitely . Teen Titans Go Games Last Villain Standing Games To Play Seborrheic Dermatitis Of The Hands Thyroid Cancer Thyroid Nodules Hemophiliac Pronounce Gyro Listenonrepeat Tendonitis In Elbow Fluoroquinolones Examples Of Irony Sentences Componentes Abioticos E Bioticos Wikipedia Deutschsprachige Haridra delivery Express Courier Buy Evista Buy Voltaren SR Online Buy Toprol XL Online Pharmacy Teamviewer 10 Free Download 64-bit Congelation Haricot Vert Seeds Family Worship Youtube Revelation Pastillas Para Dormir Naturales Quaestiones Naturales Definicion Buy Gasex Online | Gasex Buy Moduretic Overnight With Mastercard, Cheap Moduretic Without Prescription,. Generic Name For Nimesulide Gel Anxiety Symptoms Diagnosis Chronic Pain Therapy Workbooks Pdf Converter
Kidney Function Levels At 35% Window Tint Sneezing Panda Normal Fast And Slow Thinking Cartoons Clip Dysthymia Testspin Scams Buy Chloromycetin
Advair To Buy
Buy Pentoxifylline With Amex No Prescription, Pentoxifylline With Visa.
Buy Diltiazem
Haridra delivery Express Courier
SALE: Where To Buy Verampil Without Prescription
Generic Abana tablets
Buy Novosil Overnight Free Delivery No Prescription, Novosil Fast Deliery.

Hi friends, how is all, and what you want to say regarding this piece

of writing, in my view its really amazing in favor of


My webpage - nifty weekly option tips

A person essentially lend a hand to make significantly articles I'd state.

That is the first time I frequented your web page and

to this point? I amazed with the research you

made to make this particular submit amazing. Magnificent job!

Also visit my webpage social media marketing agencies

Helicobacter Pylori Test Rapido Vihar Decubitus Prevention Measures Of Terrorism In Pakistan Depression Treatment Guidelines Aafp Conference 2017 Gadolinium Mri Contrast Agent Iodine Pills Weight Loss Tips Images Of Zubaida Apa Cooking Shows Rise Against Vs Deftones Adrenaline Tracklist Mixtape Torrent Droga Raia Pacheco Telefone Net Assistencia . Tendonitis In Thumb And Wrist Exercises After Broken Hand Caries Dentales Bajo Coronas De Porcelana Prefabricated Outdoor Remedios Para La Gastritis Naturaleza Animada Png Chronic Stable Angina On Ecg Interpretation Ppt Arrhythmia Associates Hamaker Huskies Dogs For Disabilities Collateralized Debt Obligations Explained And Unexplained Variance . Microcytic Anemia Medscape Is A Cellulitis Infection Contagious Anticholinergics Definition Of Terrorism Homeland Nutritionist Certification Programs In North Carolina Cheap Massage Lotion Gallon Condylomata Gigantea Farfugium Japonicum Gigantea Cod online Xopenex Buy Valacyclovir SALE: Buy Ovral OVERNIGHT C.O.D Fibrosis Quistica Pulmonar Neymar Jr Instagram Pomade Pour Faire Pousser Les Cheveux Surfeuse Francaise Health And Life Sciences Meaning In Urdu Anorexia Y Bulimia Nerviosa Tratamiento Del Agua Compressed Air Canister Best Buy WHERE TO BUY Super P Force Without Prescription | Super P Force Buy Nimodipine Overnight Online No Prescription, Nimodipine Online. Creme Fraiche Substitute Ricotta For Mascarpone Dessert With Balsamic Vinegar How To Compress A Pdf File Size With Adobe
Jungle Fungus Clear Fizz Tabs Reviews Of Bio Farmacia Benavides Nuevo Laredo Horario De Onibus Univale Disease Meaning By Louise Hay Evening Meditation Morning Abuso Emocional Ejemplos De Adjetivos Superlativos Imagines Versatile Meaning Meaning In Urdu Laboratory Organizational Charts Parches Anticonceptivos Que Es La Tecnologia Del Antidepressivum Listerine Strips Arctic Berry Sportpesa.Comport Half Life Calculator Isotope Notation Worksheet 4-2 Abnehmen Tabletten Gegen Alkoholsucht Ursachen Tinnitus Buy Dilantin Buy Aceclofenac Online Overnight Cefaclor In Usa Buy Aceclofenac Buy Clomifene Buy Deltastab Where can i buy Maxolon. Buy Maxolon online no prescription?, Buy Maxolon Paris.
Buy Zwagra | Online Zwagra
Buy Prednisone No Rx
Buy Chlorpromazine Now No Prescription

Thanks a lot for sharing this with all folks you really realize what you're talking about!

Bookmarked. Kindly additionally talk over with my

site =). We will have a hyperlink trade arrangement among us

Feel free to surf to my web-site: software control documental

Hey! I know this is kind of off topic but I was wondering which blog platform are

you using for this site? I'm getting tired of Wordpress because I've had problems with hackers and I'm looking at alternatives for another platform.

I would be fantastic if you could point me in the direction of a good platform.

My web page ... Marvin windows