To show these elements with the class you want you can use like this: http://jsfiddle.net/caYtr/
$('#btn1').on('click', function(){
$('#conteudo p.classe1').show();
});
I’m assuming you have a CSS like this:
#conteudo p {
display: none;
}
But it would be useful to add more information to this button
to create more general and not so localized code, in case there are buttons that show other classes.
Could for example join a field data-classe
where it gathered the exact name of the class that this button should show.
Thus: http://jsfiddle.net/caYtr/2/
HTML
<button id="btn1" data-classe="classe1">Abre classe1</button>
<button id="btn2" data-classe="classe2">Abre classe2</button>
<div id="conteudo">
<p class="classe1">Teste1</p>
<p class="classe1">Teste2</p>
<p class="classe2">Teste3</p>
</div>
Javascript/jQuery
$('button').on('click', function () {
var classe = $(this).data('classe');
$('#conteudo p.' + classe).show();
});
And in this case javascript no longer needs to change, regardless of having 20 more different classes.
What do you mean by "show only"? Will this content be hidden? or should it be shown in another element?
– Sergio
This is a div with hidden content.
– mealine
What’s hidden, the entire div or what’s inside it? You can include that part of your CSS in the question?
– bfavaretto