I am showing or hiding divs elements on a single page using jQuery depending on what is clicked:
HTML:
<div id='aboutPage' class='visible'>
//content
</div>
<div id='contactPage' class='invis'>
//content
</div>
CSS:
.visible { display: block; }
.invis { display: none; }
JS:
$('#element1').on('click', {clickedTab: 'aboutTab'}, changeTab);
$('#element2').on('click', {clickedTab: 'contactTab'}, changeTab);
var currentTab = 'about';
function changeTab(event)
{
//if-else ladder to make invis the prior current tab
if (currentTab == 'about')
if (event.data.clickedTab != 'aboutTab')
$('#aboutPage').removeClass('visible').addClass('invis');
else return;
else if (currentTab == 'contact')
if (event.data.clickedTab != 'contactTab')
$('#contactPage').removeClass('visible').addClass('invis');
else return;
//if-else ladder to change the current tab
if (event.data.clickedTab == 'aboutTab') {
currentTab = 'about';
$('#aboutPage').removeClass('invis').addClass('visible');
}
else if (event.data.clickedTab == 'contactTab') {
currentTab = 'contact';
$('#contactPage').removeClass('invis').addClass('visible');
}
My question is, is it appropriate for element1
and element2
to be <a>
elements, even though they don't technically link to another page? I would like to do this so that stylistically the elements appear to be links to the user. Or, should I make them <span>
elements and then just style them to look like links using CSS? Is there any difference? Would the <a>
option be considered bad coding style?