使用jquery删除带有id的类或元素

时间:2013-04-08 04:09:30

标签: javascript jquery removeclass

我正在尝试从页面中删除一个div(最好是防止它加载)但是现在我正在解决页面加载后删除它。

我在jsfiddle上尝试了这些代码行,它可以工作。并删除'#content_gallery'div。

http://jsfiddle.net/FRYsJ/9/

<script type='text/javascript'>

$(document).ready(function(){$('#content_gallery').remove();});

</script>

但是当我将它应用到我的测试网站的头上时。它不会删除指定id的div。我也尝试用其他id标签删除其他div

测试网站:http://stage.bravo-company.info/luchatest/category/gallery/

我也试过了:

 $(document).ready(function(){        
        $('#content').remove();

 });

$(function(){
    $('#content_gallery').remove();
});

任何想法?这可能是jquery冲突的一个例子吗?我不知道如何确认这一点。

这是测试网站:http://stage.bravo-company.info/luchatest/category/gallery/

2 个答案:

答案 0 :(得分:3)

另一个JavaScript库与您网站上的jQuery冲突。解决此问题的正确方法是使用jQuery.noConflict

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
    $.noConflict();

    jQuery(document).ready(function($) {
        // Code that uses jQuery's $ can follow here.
        $(function(){
            $('#content_gallery').remove();
        });
    });

    // Code that uses other library's $ can follow here.
</script>

答案 1 :(得分:0)

这是案件冲突

使用

jquery(document).ready(function(){jquery('#content_gallery').remove();});