Title: How to change muitl divs the display which have some special id?
Tags: javascript;jquery
Question: I has some div as follows 

```<div id="span1"&gt;</div&gt;
<div id="span3"&gt;</div&gt;
<div id="span5"&gt;</div&gt;
<div id="span7"&gt;</div&gt;
.....
```

There is "span" in the id, How to show or hide them by jquery ? 


Here is the accepted answer: This should do the trick, if I understand the question correctly.

```$('[id*="span"]').hide();
```

That said, a much BETTER approach would be to put a class on all the elements you want to manipulate with the same code then use the class to hide the elements as a group.

```<div id="span1" class"span"&gt;</div&gt;
<div id="span3" class"span"&gt;</div&gt;
<div id="span5" class"span"&gt;</div&gt;
<div id="span7" class"span"&gt;</div&gt;

$('div.span').hide();
```

This is much cleaner.

Comment for this answer: Thanks! one more question ,  `function category_select(id){
 hide/show some div} `, How to pass id param to  string '[id*="/param/"]' ?
Comment for this answer: http://stackoverflow.com/questions/10672033/how-to-pass-js-code-to-string-gracefully  it's here
Comment for this answer: +1 for using the `*=`, but wouldn't `^=` do the same? assuming they all start in `span`
Comment for this answer: @Joseph - I was playing it safe. The OP said that span was "in" the ID so I wasn't sure we could count on it being a prefix.
Comment for this answer: @why I think you should post a separate question for that. The format of this site works better that way. In any case. Go with the second option it is a much better approach anyway.

Here is another answer: you can put the selectors of the ones to hide in an array and join then with a comma:

```var tohide = [
    "#span1",
    "#span3",
    "#span5",
    "#span7"
];

$(tohide.join(',')).hide();
```



or, add a common class to each:

```<div class="tohide" id="span1"&gt;</div&gt;
<div class="tohide" id="span3"&gt;</div&gt;
<div class="tohide" id="span5"&gt;</div&gt;
<div class="tohide" id="span7"&gt;</div&gt;

$('.tohide').hide();
```

Comment for this answer: Actually, you don't even need `.join(',')`, `toString()` is enough. But clever solution!
Comment for this answer: +1 - Very clever solution. Thinking outside the box today are you?

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:05/20/12', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<javascript><jquery>', 'Title': 'How to change muitl divs the display which have some special id?', 'ViewCount': 48, 'id': 10671865, 'user_AboutMe': '', 'user_AccountId': 133823.0, 'user_DisplayName': 'why', 'user_Reputation': 22893.0, 'user_Views': 1507.0, 'user_id': 335499.0}}