开发者

jQuery: Hide div with no ID

开发者 https://www.devze.com 2023-04-09 07:53 出处:网络
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?

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.

jQuery: Hide div with no ID

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

Thanks alot.


Try this:

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

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

fiddle: http://jsfiddle.net/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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号