开发者

JQUERY Refined Selection

开发者 https://www.devze.com 2023-03-29 03:06 出处:网络
I wanted to ask about the best way to write this JQUERY code. I have DOM structure like this: <div id=\"chatCenterMembers\">

I wanted to ask about the best way to write this JQUERY code. I have DOM structure like this:

 <div id="chatCenterMembers">
   <div id="adam" class="chatmember 100">
      <div cl开发者_如何学Cass="newchatmessage" style="display: block;"></div>
   </div>
   <div id="steven" class="chatmember 101">
      <div class="newchatmessage"></div>
   </div>
 </div>

I want to extract a list of userid's - eg: 100, 101 class names into array where the DIV with class "newchatmessage" has the style set to display block - eg: its visable.

I can do it with a $.each loop but its appears inefficient.

Is there a better way? thx


You could collect all needed visible elements just like that:

$(".chatmember .newchatmessage").filter(":visible").each(function() 
{
    //Extract here any information you want, i.e. 
    //this.className.match(/[0-9]+/) 
});


Try this code:

$('.newchatmessage').map(function(){
if ($(this).css('display') == 'block')
  return $(this).parent().attr('class').replace('chatmember ','');
}).get();
0

精彩评论

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