webForumDet fria alternativet

Sätta class på länk

0 svar · 297 visningar · startad av redaktören

redaktörenMedlem sedan mars 20083 inlägg
#1

Hej på er! Har ett lite bekymmer här. Det är så att jag har en perfekt fungerande JS script som visar och döljer divar vid länktryckning. Frågan kommer längst ner :)

showhide.js

//here you place the ids of every element you want.
var ids=new Array('newrecent','newcomments');

function switchid(id){	
	hideallids();
	showdiv(id);
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

Sidebar.php

<div id="sidebar">

<div id="recenttopic">
    
		<a href="javascript:switchid('newrecent');">Nyaste</a>
        
		<a href="javascript:switchid('newcomments');">Kommentarer</a>
        
		</div>	

	<div class="recentsidebar">

        
		<div id='newrecent' style="display:block;">
			
         	<ol>
  			<?php
   			$lastposts = get_posts('numberposts=10');
   			foreach($lastposts as $post) :
    		setup_postdata($post);
   			?>
   				
                <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
   			
			<?php endforeach; ?>
            
		</ol>
        
	</div>

	<div id='newcomments' style="display:none;">
		
        <ol>
		<li>Här visas kommentarer</li>
        </ol>
	
	</div>

</div>

</div>

Detta fungerar som sagt kanon bara det att jag vill att länken som är till diven som är aktiv (show), ska få classen .current. Hur får jag ihop det?

127 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
125 ms — hämta tråd, inlägg och bilagor (db)