Home > Enterprise >  How can i Load only a selected part of webpage in chrome when it load by JS or Jquery
How can i Load only a selected part of webpage in chrome when it load by JS or Jquery

Time:10-07

My problem is that i want to remove all other content from a webpage except some div just like something in read only mode of browser.

Is it possible to remove all other HTML element just like <script>...</script> , <div>...</div>

except some div class that i want to keep on page like: <div class="someone">...</div>

i tried this one : How can i remove all div's and other DOM HTML elements except a particular class using jQuery but not completing my target :

is there some best tips available to done my job.

CodePudding user response:

You can try this code $('body *:not(.someone)').remove()

CodePudding user response:

You can do it this way to remove everything but your wanted elements:

$(document).ready(function(){
  var x = $('.exclude');
  $('body').html(x);
});

Here is a sample:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  var x = $('.exclude');
  $('body').html(x);
});
</script>
</head>
<body>
<h1 class="exclude">Excluded heading</h1>
<p>I will disappear.</p>
<p class="exclude">I will remain in the page.</p>
<p class="exclude">Me Too!</p>
<p>Some text...</p>
<p>Some text...</p>

Some text...Some text...Some text...

</body>
</html>

  • Related