0

I'm trying to remove an entire div on page load. Currently I'm trying to use:

$(document).ready(function(){    
    $("#removeme").remove();
});

with the HTML

<div id="removeme">If JS enabled remove this!</div>

I've been searching for hours, using many variations including getElementById. No luck.

Javascript/jQuery aren't languages I use often.

All help is appreciated. Thanks!

Edit: Fixed, page I was adding it to was having some issues (another dev built it). I put the code into an existing JS file instead and it works. Thank you all.

Nick Moreau
  • 11
  • 1
  • 1
  • 4

3 Answers3

2
$('#remove').html('');

or

$('#remove').empty();

That will remove that text if JS is enabled.

kunal18
  • 1,935
  • 5
  • 33
  • 58
1

The code you are showing in your question works, as proven by @barmar :

"http://jsfiddle.net/barmar/epsZe/"

If it doesn't work for you, it is most likely because you have an error in your Javascript before you reach the code displayed here. Also, ensure that you have included Jquery before-hand.

To find where previous errors could have happened, you can look inside your Javascript console. Here is a question where it is described where to find your console on most browsers :

What is console.log and how do I use it?

If you don't want to use the console, you can put alerts in your Javascript code until you find where they stop displaying.

Community
  • 1
  • 1
Dany Caissy
  • 3,176
  • 15
  • 21
  • Thanks i'll give that a try. Yeah I just tested it myself on a blank page and it worked perfect. However on the site I'm trying to actually have it work on its not. I'll try the console. Thank you everyone. – Nick Moreau Jul 04 '13 at 20:13
  • Thanks for the replies. I just checked the console and I got the following error: Uncaught TypeError: Property '$' of object [object Object] is not a function. HTML, CSS, PHP are all easy but javascript drives me nuts :) – Nick Moreau Jul 04 '13 at 20:20
  • Let's just say Javascript is...special :) – Dany Caissy Jul 04 '13 at 20:28
0

try this $("#removeme").replaceWith("");

user
  • 539
  • 1
  • 11
  • 32