AVeryNiceWeb

[Javascript] Remove content from HTML

[Javascript] Remove content from HTML

Postby admin » Mon May 22, 2017 9:15 pm

In this example we will remove the contents of specified div elements.

Paste this code in the <head> and before the </head>:
Code: Select all
<SCRIPT LANGUAGE="JavaScript">

javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){

$( init );

function init() {

  // Delete the contents of #myDiv1 and #myDiv2
  $('.emptyMe').empty();
}
});

</SCRIPT>


Use this HTML as an example:
Code: Select all
  <div class="emptyMe" id="myDiv1">
    <p>I am not needed</p>
  </div>

  <div class="emptyMe" id="myDiv2">
    <p>I can be removed</p>
    More text node and on its own
  </div>
The AVNW Support Team
http://www.AVeryNiceWeb.com

We also have great domain names for your next website. Go through the list and make an offer now!

Shopping for a new website? See our design deals.

How much is your website worth? Get a free estimate.

And, if our post has provided you with great information, there are a few ways you can show your appreciation:
  1. Like us on Facebook
  2. Post a review.- Posting a good review about this site could help us provide improved support.

Thank You!
User avatar
admin
Site Admin
 
Posts: 466
Joined: Sun Jan 12, 2014 11:18 pm
Location: New York City

Re: [Javascript] Remove content from HTML

Postby admin » Tue May 23, 2017 4:00 pm

In this example you can select the element with more precision.

Paste this code in the <head> and before the </head>:
Code: Select all
<SCRIPT LANGUAGE="JavaScript">

javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){

var child = $('#firstDiv').children('span');

$('#firstDiv').html(child);


});

</SCRIPT>


Use this HTML as an example and paste it in the body of the page:
Code: Select all
<div id="firstDiv">
    This text should be removed...
    <span id="firstSpan">First span (no change)</span>
    <span id="secondSpan">Second span (no changes also)</span>
</div>
The AVNW Support Team
http://www.AVeryNiceWeb.com

We also have great domain names for your next website. Go through the list and make an offer now!

Shopping for a new website? See our design deals.

How much is your website worth? Get a free estimate.

And, if our post has provided you with great information, there are a few ways you can show your appreciation:
  1. Like us on Facebook
  2. Post a review.- Posting a good review about this site could help us provide improved support.

Thank You!
User avatar
admin
Site Admin
 
Posts: 466
Joined: Sun Jan 12, 2014 11:18 pm
Location: New York City


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron