Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> dynamiczne zmiana class w linku
marcus755
post
Post #1





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

Ostrzeżenie: (0%)
-----


dynamiczne zmiana class w linku,
czyli klikam na link 2 znika miactive z link1,
klikam link3 i znika mi z link 2, itd.

a ten skrypt poniżej, nie wiem dlaczego jak klikam to pokazuje active na kliknięcie, ale nie robi remove z poprzedniego linka.
Co jest nie tak?

<nav id="menu">
<ul>
<li><a class="active" href="#"><span>link 1</span></a></li>
<li><a href="#"><span>link 2</span></a></li>
<li><a href="#"><span>link 3</span></a></li>
<li><a href="#"><span>link4</span></a></li>
</ul>
<script>
$('#menu a').click(

function(e) {
e.preventDefault(); // prevent the default action
e.stopPropagation; // stop the click from bubbling
$(this).closest('a').find('.active').removeClass('active');
$(this).addClass('active');
});
</script>
</nav>

Ten post edytował marcus755 18.01.2013, 11:23:36
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 5)
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




nie: $(this).closest('a').find('.active').removeClass('active');
a: $('.active').removeClass('active');
Go to the top of the page
+Quote Post
marcus755
post
Post #3





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

Ostrzeżenie: (0%)
-----


O Wielki Milordzie:-)
Dziękuję za Pomoc,
jesteś Wielki i to bez ściemy:-)
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Poprostu wyznaję zasadę: jak można zrobić coś prosto, robię to prosto a nie wymyślam 15 funkcji dookoła (IMG:style_emoticons/default/wink.gif)
Go to the top of the page
+Quote Post
marcus755
post
Post #5





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

Ostrzeżenie: (0%)
-----


a dla 2 menu z tym samym active - da się?
Bo teraz jak klikam w pierszy, to usuwa mi w drugim menu i na odwrót,
gdzie pierwsze menu z <nav id="menu">, a drugie <nav id="menu2">
Go to the top of the page
+Quote Post
nospor
post
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




No to szukaj active tylko w obrębie danego menu - praca domowa dla Ciebie (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 16:16