最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin16PV0评论

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far