最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin7浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论