You can do it this way
Html
<ul>
<li>
<a class="active">Opção 1</a>
</li>
<li>
<a class="">Opção 2</a>
</li>
</ul>
<div class="content active">Mostrar conteúdo 1</div>
<div class="content">Mostrar conteúdo 2</div>
CSS
a {
cursor: pointer;
}
li a.active {
border-bottom: 2px solid #000;
}
.content {
display: none;
}
.content.active {
display: block;
}
Jquery
$(function(){
$('ul li a').click(function(i){
$('ul li a').removeClass('active');
$(this).addClass('active');
$('.content').each(function(index) {
$(this).toggleClass('active');
});
});
});
Clicking it removes the 'active' from all 'a' and toggles between contents.
Example: link
I've done everything to not change the html and css, it's working, but
it would be nice to put a handle to each content you want
shows, because this way will work with only two elements.
Using date for identification
HTML
<ul>
<li>
<a class="active" data-id='1'>Opção 1</a>
</li>
<li>
<a class="" data-id='2'>Opção 2</a>
</li>
</ul>
<div class="content active" data-id='1'>Mostrar conteúdo 1</div>
<div class="content" data-id='2'>Mostrar conteúdo 2</div>
I put a date-id to identify your relationship
CSS
a {
cursor: pointer;
}
li a.active {
border-bottom: 2px solid #000;
}
.content {
display: none;
}
.content.active {
display: block;
}
The same css
JQUERY
$(function(){
$('ul li a').click(function(){
$('ul li a').removeClass('active');
$('.content').removeClass('active');
$(this).addClass('active');
var id = $(this).data('id');
var content = $('.content').filter(function() {
return $(this).data("id") == id
});
content.addClass('active');
});
});
So the action is performed according to its identifier, so you can create new elements without worrying about changing jquery.
Example: link