Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JS][Jquery]Usunięcie elementu, jednak nie takie proste
grzes999
post
Post #1





Grupa: Zarejestrowani
Postów: 305
Pomógł: 29
Dołączył: 5.07.2011

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


To znowu ja problem może wydać się banalny jednak nie mogę sobie z nim poradzić :/
Mam taki kod JS do dodawania i usuwania diva z zawartoscią.

  1. $(function () {
  2. $('[id="kl"]').click(function () {
  3. $(this).parent().remove();
  4. })
  5. $('#pokaz').click(function () {
  6. $('#elementy').append(
  7. '<div id="cos">'+
  8. '<h1>Pierwsze</h1>'+
  9. '<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>'+
  10. '<button ="kl">usun</button>'+
  11. '</div>'
  12. )
  13. })
  14.  
  15. })


I taki kod strony

  1. <a href="#" id="pokaz">Odkryj element</a>
  2. <div id="elementy">
  3. <div id="cos">
  4. <h1>Pierws11ze</h1>
  5. <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
  6. <button id="kl">usun</button>
  7. </div>
  8. </div>


I przycisk ten który jest w html usuwa mi diva a ten który wygeneruję za pomocą javascriptu już nie (IMG:style_emoticons/default/co_jest.gif)
Wiem, że niby każdy przycisk powinien mieć swoje id ale wiem że tak też się da.


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





Grupa: Zarejestrowani
Postów: 113
Pomógł: 14
Dołączył: 25.08.2006

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


Zamiast:

  1. $('[id="kl"]').click(function () {


Powinno być:

  1. $('[id="kl"]').live('click', function () {
Go to the top of the page
+Quote Post
grzes999
post
Post #3





Grupa: Zarejestrowani
Postów: 305
Pomógł: 29
Dołączył: 5.07.2011

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


Wielkie dzięki za pomoc.
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.09.2025 - 02:33