Kastriot Kosumi
Kastriot Kosumi

Reputation: 47

Remove script after clicking in a div

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>

Upvotes: 2

Views: 816

Answers (3)

James
James

Reputation: 1678

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).

Upvotes: 1

edencorbin
edencorbin

Reputation: 2939

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()

Upvotes: 2

7urkm3n
7urkm3n

Reputation: 6321

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

$('#fbb').on('click', function(){
    $(this).hide();
})

Upvotes: 0

Related Questions