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 :

HTML

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

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

Javascript

  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.

CSS

  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 :

Conclusion

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.

Commentaires

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 (www.Zaizhuli.com)

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

This is really interesting, You are a very skilled

blogger. I've joined your rss feed and look forward to seeking more

of your magnificent post. Also, I've shared your website in my social networks!

My page Dong

Right now it appears like BlogEngine is the best blogging

platform available right now. (from what I've read) Is

that what you are using on your blog?

Here is my webpage corporate proxy solicitation investopedia forex

Hello there, just became aware of your blog through Google, and found that it's really informative.

I'm going to watch out for brussels. I'll appreciate

if you continue this in future. A lot of people will be benefited from

your writing. Cheers!

My weblog :: Simracinglinks.Com

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.

Thanks

my homepage - escorts melbourne (www.adposta.com)

It is appropriate time to make a few plans for the long run and it is

time to be happy. I have learn this post and if I could I desire to counsel you few attention-grabbing things or suggestions.

Perhaps you can write next articles referring to this article.

I desire to learn even more issues approximately it!

Take a look at my webpage Proxy Solicitation Fraud

I always used to read article in news papers but now as I am a user

of internet so from now I am using net for content, thanks to web.

my web page; Corporate proxy solicitation regulations meaning

Wow, marvelous weblog layout! How lengthy have you been blogging for?

you made blogging glance easy. The full glance of your site is great, as neatly as the content!

Visit my blog post :: laurel hill proxy solicitation Job

Nice blog here! Also your web site loads up fast! What web host are you using?

Can I get your affiliate link to your host?

I wish my website loaded up as fast as yours lol

Also visit my site corporate proxy solicitation Companies

Fantastic post however I was wanting to know if you could write

a litte more on this topic? I'd be very grateful if you could elaborate a little bit further.

Cheers!

my homepage praxis ii

Hi this is kinda of off topic but I was wanting to know if blogs use WYSIWYG editors

or if you have to manually code with HTML. I'm starting a blog soon but have

no coding knowledge so I wanted to get guidance from someone with experience.

Any help would be greatly appreciated!

My page Download site

Does your website have a contact page? I'm having trouble locating it but, I'd like

to send you an e-mail. I've got some suggestions for your

blog you might be interested in hearing. Either way,

great blog and I look forward to seeing it improve over time.

my web site; Harriett

bookmarked!!, I love your website!

My web page ... corporate proxy solicitation regulations In healthcare

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 . http://www.currensyspitta.com/forum/buy-amantadine-fast-deliery-amantadine-2514666 http://www.chennaiputhagasangamam.com/2014/?option=com_k2&view=itemlist&task=user&id=79942 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
https://mewnowtv.com/forums/topic/buy-fluconazole-order-mastercard-buy-cheap-fluconazole/ 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.
http://www.erbilchamber.org/?option=com_k2&view=itemlist&task=user&id=34171
Buy Diltiazem
http://www.dodokar.com/?option=com_k2&view=itemlist&task=user&id=102334
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

me.

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

My coder is trying to persuade me to move to .net from PHP.

I have always disliked the idea because of the expenses. But he's tryiong

none the less. I've been using Movable-type on a variety of

websites for about a year and am anxious about switching to another platform.

I have heard good things about blogengine.net. Is there

a way I can import all my wordpress content into it?

Any kind of help would be greatly appreciated!

Also visit my webpage; corporate proxy solicitation investopedia forex

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
https://getprotvnow.com/forums/topic/buy-medrol-no-prescription-us-medrol-without-prescription/ Cod online Xopenex http://vario-helicopter.be/forums/topic/buy-proscar-online-proscar-order-proscar-mastercard/ 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 http://www.how2dodigitalmarketing.com/forums/topic/buy-rogaine-2-money-order-rogaine-2-buy-rogaine-2-no-prescription/ 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 http://www.indiecade.com/ingademo/node/98829 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.
http://www.elmiradordecieza.com/Index/?option=com_k2&view=itemlist&task=user&id=14050
Buy Zwagra | Online Zwagra
Buy Prednisone No Rx
Buy Chlorpromazine Now No Prescription
https://www.sxk.se/forumtopic/order-combimist-l-inhaler-price-usa-buy-combimist-l-inhaler-pierre

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

Thanks in favor of sharing such a nice thought, paragraph is pleasant, thats why

i have read it entirely

my weblog ... proxy Solicitation firms top ten

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

Amazing blog! Do you have any tips for aspiring writers?

I'm planning to start my own website soon but I'm a

little lost on everything. Would you recommend starting

with a free platform like Wordpress or go for a paid option? There are

so many choices out there that I'm totally confused ..

Any ideas? Thanks a lot!

Stop by my page :: Wise Study

Appreciating the commitment you put into your site

and in depth information you offer. It's great

to come across a blog every once in a while that isn't the same outdated rehashed material.

Excellent read! I've bookmarked your site and I'm including your RSS feeds to my Google account.

Here is my web-site; proxy solicitation process

Attractive component to content. I simply stumbled upon your website and in accession capital to assert that

I acquire in fact loved account your weblog posts.

Anyway I'll be subscribing in your feeds and even I achievement you get

entry to consistently fast.

Check out my weblog ... laurel hill proxy solicitation regulations

A person essentially assist to make critically articles I might state.

That is the very first time I frequented your

website page and to this point? I surprised with the analysis you made to make this actual put up amazing.

Magnificent activity!

My webpage Broadridge Proxy Solicitation Investopedia

This article will assist the internet viewers for creating new webpage

or even a weblog from start to end.

Look at my website :: Download

Terrific work! That is the kind of info that are supposed to be shared across the net.

Disgrace on Google for no longer positioning this put up higher!

Come on over and consult with my website . Thanks

=)

Here is my webpage marketing Strategy

Yes! Finally someone writes about corporate proxy solicitation regulations governing.

Here is my weblog :: Blogvietkieu.Com

Nice answer back in return of this query with real arguments and describing everything on the topic of that.

My page ... corporate proxy solicitation Rules would apply to which of the following

Appreciate this post. Will try it out.

Also visit my web site; corporate proxy solicitation rules would apply to which of The following

Aw, this was an incredibly nice post. Taking a few minutes

and actual effort to make a really good article… but what can I say… I procrastinate a lot and don't seem to get nearly anything done.

Feel free to visit my site Download site