2
//style
.TemplateBox1{display:none;} 

//Html
<div class="TemplateBox1" id="9">  1 </div>
<div class="TemplateBox1" id="10"> 2 </div>
<div class="TemplateBox1" id="11"> 3 </div>

//jQuery
$('div', this).each(function (e) { //Do something  });

This is a part from my code, at start the divs display (CSSproperty) is none (not shown) and after the user click on a certain button the property of the div changed to block (shown). I need to select only the divs that their property is display:block using jQuery, I tried :

$('div', this).**css("display")=="block"**.each(function (e) { //Do something  }); - didn't work..

What do I need to add to my jQuery...

3
  • 1
    $('div:visible', this).each(function (e) { }); Commented Jul 22, 2014 at 10:53
  • 1
    Note that in HTML4, IDs should begin with a letter. HTML5 is more permissive, but CSS won't target an ID that begins with a number. Commented Jul 22, 2014 at 10:56
  • Thank you, I am using HTML5 Commented Jul 22, 2014 at 11:00

4 Answers 4

6

Try to use :visible selector,

$('div:visible')

It seems that you are using TemplateBox1 class to hide those elements, so you can write in this manner too, that is by using :not() selector

$('div:not(.TemplateBox1)')
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, will accept it as an answer in a few minutes :)
5

Try this : :visible selector for div

$(this).find('div:visible').each(function(){
 // do stuff here
});

Comments

0

one way is $('div:visible')

another way is (Demo)

$('.TemplateBox1', this).each(function (e) {
    var $css = $(this).css('display');
    if($css == 'none'){
        $(this).css('display','block')
    }
});

Comments

0

Why not use pure JS ?

var list = document.getElementsByTagName("div");
foreach(var i = 0;i < list.length, i++)
{ 
   if(list[i].style.display == "block")
    {
      // do Something;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.