admin管理员组

文章数量:1313133

How can I hide a div with no ID? I have an application which creates few stickies. Some of them have no ID and some of the do have. How can I hide the ones with no ID?

The position is not always the same.

This is what I get in the HTML where I want to hide the last one.

Is it possible I can hide the one with no ID? Note that the rest which have ID's, is a number generated randomly.

Thanks alot.

How can I hide a div with no ID? I have an application which creates few stickies. Some of them have no ID and some of the do have. How can I hide the ones with no ID?

The position is not always the same.

This is what I get in the HTML where I want to hide the last one.

Is it possible I can hide the one with no ID? Note that the rest which have ID's, is a number generated randomly.

Thanks alot.

Share Improve this question asked Sep 27, 2011 at 17:58 jQuerybeastjQuerybeast 14.5k39 gold badges119 silver badges198 bronze badges 1
  • Will there only be a single div with class sticky that needs to be hidden? – Larsenal Commented Sep 27, 2011 at 18:01
Add a ment  | 

2 Answers 2

Reset to default 6

Try this:

$("div.sticky:not([id])").hide();

The main idea is to use :not([id]) selector with element selector.

fiddle: http://jsfiddle/57uQ8/

http://sandbox.phpcode.eu/g/d2956/2

<script>
$(function(){
    $("div.sticky").each(function(b){
        if (!$(this).attr('id')){
            $(this).hide(); 
        }
    });
});
</script>

will probably do it, assuming you want to show ONLY divs with no IDS and divs with class sticky

本文标签: javascriptjQuery Hide div with no IDStack Overflow