JQuery conflict when deleting div after page load

I am trying to remove a div from the page (it is desirable that it does not load at all), but now I agree to delete it after the page loads.

When I try the following lines of code in jsFiddle , the div #contentis deleted as expected.

<script type='text/javascript'>//<![CDATA[ 
  $(window).load(function(){
      $('#content').remove();
  });//]]>  
</script>

However, I also tried to implement it on the actual website , but in this case the div is #contentnot deleted.

Any suggestions as to what might be wrong?

+5
source share
8 answers

If you are sharing jQuery with another library that uses the dollar for its work, you need to protect yourself from it this way using an anonymous shell:

(function($) {
    $(window).on('load', function(){
        $('#content').remove();
    });
}(jQuery));

, .load() .on('load', fn).

DOM ready; jQuery :

jQuery(function($) {
    $('#content').remove();
});
+2

$ jQuery - .

<script type='text/javascript'>
    window.$ = jQuery;
    $(window).load(function()
    {

        $('#content').remove();
     });
</script>
+1

:

<script type="text/javascript">
var node = document.getElementById('content'); 
if(node.parentNode)
{ 
node.parentNode.removeChild(node);
}
</script>

.

0

<script type='text/javascript'> 
    $(document).ready(function(){
         $('#content').remove();
    });
</script>

$(function()
{
        $('#content').remove();
});
0

, $(window).load() javascript.

Uncaught TypeError: Object [object global] has no method 'load'

, document.ready, ( ).

//shorthand for $(document).ready()
$(function(){
    $('#content').remove();
});
0

TypeError: $(...). load

, , JQuery

$(window).load(function(){
});

$(function(){
 // your code here
})
0

You are using jQuery testing with onload,

so you need to add onload syntax in jquery, the operator does not call onload on your site, so it doesn't work

I updated the fiddle

http://jsfiddle.net/MarmeeK/FRYsJ/3/

JS code in the tag <script>without adding to onload on the page,

<script type="text/javascript">
    $(document).ready(function(){$('#content').remove();});
</script>

this should work :)

0
source

Case with jquery conflict. The page also has a mootools structure.

I also made a "view source" of the page, and I recognized this line

$j = jQuery.noConflict();  //line 132

So try this

$j('#content').remove();
Or
jQuery('#content').remove();
0
source

All Articles