Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Podmiana diva w javascript
binprogrammer
post 9.05.2013, 21:45:40
Post #1





Grupa: Zarejestrowani
Postów: 249
Pomógł: 8
Dołączył: 10.08.2011
Skąd: Bełchatów

Ostrzeżenie: (10%)
X----


Witam, chcę zrobić skrypt do temparmonkey i wie ktoś z Was jak podmienić diva?

np. mam <div id=trolo">tresc</div> i chcę zamienić na <div id="trolo" cos="trolo">tresc</div> możecie mi coś podpowiedzieć?
Go to the top of the page
+Quote Post
Szymciosek
post 9.05.2013, 21:55:25
Post #2





Grupa: Zarejestrowani
Postów: 1 168
Pomógł: 126
Dołączył: 5.02.2010
Skąd: Świdnica

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


http://api.jquery.com/attr/

Patrz w examples.
Go to the top of the page
+Quote Post
binprogrammer
post 10.05.2013, 13:55:45
Post #3





Grupa: Zarejestrowani
Postów: 249
Pomógł: 8
Dołączył: 10.08.2011
Skąd: Bełchatów

Ostrzeżenie: (10%)
X----


Nie rozumiem, mam div na stronie <div class="klasa1"><h1>trolo</h1></div> i we wtyczce temparmonkey muszę podmienić na <div class="klasa1"><h1 class="klasa2">trolo</h1></div> wiecie może jak to najłatwiej zrobić?

  1. var my_div = null;
  2. var newDiv = null;
  3.  
  4. function addElement()
  5. {
  6. // tworzy nowy element div
  7. // i daje jego zawartość
  8. newDiv = document.createElement("div");
  9. newDiv.innerHTML = "<h1>trolo</h1>";
  10.  
  11. // add the newly created element and it's content into the DOM
  12. my_div = document.getElementByClass("klasa1");
  13. document.body.insertBefore(newDiv, my_div);
  14. }


W tą stronę idę, ale nie wiem czy dobrze
Go to the top of the page
+Quote Post
Szymciosek
post 10.05.2013, 14:29:15
Post #4





Grupa: Zarejestrowani
Postów: 1 168
Pomógł: 126
Dołączył: 5.02.2010
Skąd: Świdnica

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


http://jsfiddle.net/byCz3/
Go to the top of the page
+Quote Post
binprogrammer
post 10.05.2013, 15:44:22
Post #5





Grupa: Zarejestrowani
Postów: 249
Pomógł: 8
Dołączył: 10.08.2011
Skąd: Bełchatów

Ostrzeżenie: (10%)
X----


Dzięki wielkie, a jak dodać inny atrybut niż klasę? myślałem, żeby takie coś zrobić

Kod
$(document).ready(function() {
    //znalezienie obiektu
    var el = $('.klasa_diva').children('input');
    
    //dodanie atrybutu
    el.setAttribute('onfocus', onInputFocus(this));
    el.setAttribute('onblur', onInputBlur(this));
    el.setAttribute('value', binprogrammer);
});


ale nie działa

Ten post edytował binprogrammer 10.05.2013, 15:52:28
Go to the top of the page
+Quote Post
Szymciosek
post 10.05.2013, 23:23:04
Post #6





Grupa: Zarejestrowani
Postów: 1 168
Pomógł: 126
Dołączył: 5.02.2010
Skąd: Świdnica

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


http://jsfiddle.net/ps8Ay/
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 18.04.2024 - 09:12