javascript - jQuery, show all elements by class name - Stack Overflow

admin2025-02-14  19

I want to show all elements with some class name (string). Something like:

var somevar = "apple"
$( .... select all elements with class == somevar  ).show();

How can it be done?

I want to show all elements with some class name (string). Something like:

var somevar = "apple"
$( .... select all elements with class == somevar  ).show();

How can it be done?

Share Improve this question asked Aug 31, 2010 at 19:49 There Are Four LightsThere Are Four Lights 1,4263 gold badges20 silver badges35 bronze badges 1
  • 4 5 answers and all the same. Must be correct :) – Marko Commented Aug 31, 2010 at 19:52
Add a comment  | 

5 Answers 5

Reset to default 7

$("." + somevar).show()

I think it should be as simple as

$('.' + somevar).show();
$("." + somevar).show();
$(document).ready(function(){

  var somevar = ".apple"

      $(somevar).show();

});​

That will show .apple

OR

$(document).ready(function(){

  var somevar = "apple"

      $('.' + somevar).show();

});​

$('.'+somevar).show();

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1739491685a109006.html

最新回复(0)