admin管理员组

文章数量:1026989

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();

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();

本文标签: JavaScriptJQueryshow all elements by class nameStack Overflow