Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting HTML code without being affected by CSS and Jquery

I want to insert some HTML code inside a page, the code I insert should not be affected by the CSS and JS of that page, it should load it's own CSS and JS.

Example Code:

<div class="body">
  <p>Example Content </p>
  <p>Sample Content 2 </p>
  <div class="special-div">
      <p> No CSS and JS to be applied to this div 'special-div', it should load it's own CSS and JS </p>
  </div><!-- /.special-div -->
</div><!-- /.body -->

In the above code div with class "special-div" should load it's own CSS and JS and should not be affected by page's CSS and JS

I've tried using iframes but firstly they are cross origin, secondly iframe has it's own scroll bar.

I am trying to insert a slider into wordpress page, I've built slider in a HTML site and tested it but the default wordpress styles and JS are changing the layout. I can easily remove the styles but I'm not sure how to get rid of the JS which is affecting the slider

Any help would be appreciate.

like image 986
chandan Avatar asked Apr 10 '26 09:04

chandan


1 Answers

One way of doing it is Shadow DOM.

Shadow DOM provides encapsulation for the JavaScript, CSS and templating in a Web Component. Shadow DOM makes it so these things remain separate from the DOM of the main document. You can also use Shadow DOM by itself, outside of a web component.

like image 117
Ruslanas Balčiūnas Avatar answered Apr 11 '26 22:04

Ruslanas Balčiūnas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!