2

I want do remove the div with id="fbb" after i click on it. Please help

Here is my code:

<script type="text/javascript">
function hide() {
    document.getElementById('fbb').style.display = 'none';
}
<script>
<div style="position:absolute;left:50px;top:60px;opacity:1.1;z-index:9999;" id="fbb" onclick="hide()">
<script type="text/javascript">
    google_ad_client = "";
    google_ad_slot = "";
    google_ad_width = ;
    google_ad_height = ;
</script>
<!-- casorla-bet_main_Blog1_300x250_as -->
<script type="text/javascript" target="_blank" class="test" src="#">
</script>
</div>
  • 3
    If you google for your issue you will find lots of answers – Keith M Jan 14 '16 at 00:45
  • remove is different from hide.. what you're doing is just hidding it.. I would recommend doing in jquery something like this `$('#fbb').remove()` – Drixson Oseña Jan 14 '16 at 00:45
  • This question has the jQuery tag but has nothing to do with it. If you're using jQuery you don't need to make a hide() function. – Phiter Jan 14 '16 at 00:47
  • Possible duplicate of [How to delete li element in ajax response function](http://stackoverflow.com/questions/12870479/how-to-delete-li-element-in-ajax-response-function) – Keith M Jan 14 '16 at 00:51
  • check this link http://www.w3schools.com/js/js_htmldom_nodes.asp It covers creating and removing elements..good luck – repzero Jan 14 '16 at 00:54
  • check this answer you will find exactly what you need http://stackoverflow.com/questions/5933157/how-to-remove-an-html-element-using-javascript – mustafa-elhelbawy Jan 14 '16 at 00:56
  • 1
    you can just pass the object of the div in your method and use`.remove`. try this https://jsfiddle.net/eqgj2s1n/ – Sushil Jan 14 '16 at 00:57
  • What's the point of removing a script? The script already ran when the page was loaded, removing it won't have any effect on the code. – Barmar Jan 14 '16 at 01:07

3 Answers3

2

Replace your code line:

document.getElementById('fbb').style.display = 'none';

with either javascript:

var element = document.getElementById("fbb");
element.parentNode.removeChild(element);

Or as posted above, with jQuery:

$('#fbb').remove()
edencorbin
  • 2,569
  • 5
  • 29
  • 44
  • 1
    Oh, that is confusing I meant replace your code (that first line), with either pure javascript (the second line), or jquery (the third line). Thanks for the correction. – edencorbin Feb 15 '16 at 01:28
1

Just like this, with jQuery:

$( "#fbb" ).remove();

Or, with vanilla JavaScript:

document.getElementById("fbb").remove();

The JavaScript example might not work with older browsers (which basically means older IE).

James
  • 1,568
  • 1
  • 15
  • 25
0

Also, you can use and ".hide()" method with Jquery. Then add ".show()", if its temporarily.

$('#fbb').on('click', function(){
    $(this).hide();
})
7urkm3n
  • 6,054
  • 4
  • 29
  • 46