Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript] Dodawanie klasy + span
Lolek13
post
Post #1





Grupa: Zarejestrowani
Postów: 121
Pomógł: 4
Dołączył: 21.02.2012
Skąd: Gliwice

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


Witam wszystkich,

Mam takie przykladowe menu:

  1. <ul class="menu_level_1">
  2. <li><a href="#">1</a></li>
  3. <li><a href="#">1</a></li>
  4. <li><a href="#">1</a></li>
  5. <li><a href="#">1</a></li>
  6. <li><a href="#" class="active"><span class="round_left"></span>TEKST<span class="round_right"></span></a></li>
  7. </ul>


Po kliknieciu w dany link chce za pomoca JS dodawac klase active + te 2 znaczniki span z prawej i lewej strony tekstu. Jak najlepiej sie za to zabrac ?

Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
john_doe
post
Post #2





Grupa: Zarejestrowani
Postów: 873
Pomógł: 25
Dołączył: 24.07.2005

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


jQuery addClass, removeClass, ToggleClass,
Go to the top of the page
+Quote Post
viking
post
Post #3





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


  1. var el = document.querySelector(".menu_level_1");
  2. el.addEventListener("click", function(e){
  3. if(e.target && e.target.nodeName == "A") {
  4. e.target.classList.add("active");
  5. _appendSpan(); //tutaj <a href="https://developer.mozilla.org/en-US/docs/DOM/document.createElement" target="_blank">https://developer.mozilla.org/en-US/docs/DO...t.createElement</a>
  6. }
  7. }, false);


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: 25.08.2025 - 02:22