View previous topic :: View next topic |
Author |
Message |
nel`chee
Joined: 08 Jul 2004 Posts: 2087 Location: Rijeka
|
Posted: 03.12.2006 16:09 Post subject: JS: getAttribute problem |
|
|
Code: | function exitLinks() {
var exitLink=document.getElementsByTagName('a');
for (var i = 0; i<exitLink.length; i++) {
if (exitLink[i].getAttribute("rel") == "offsite") {
exitLink[i].className = 'exit';
}
}
}
} |
pozivanje funkcije i dohvaćanje linkova radi, ali ovaj getAttribute neće.
pokušavam dobiti klasu za IE pošto ne kuži a[rel~="offsite"] |
_________________ ♥ art & design portfolio ♥ free Photoshop brushes stuff ♥ sketchblog ♥ facebook ♥ |
|
Back to top |
|
|
strija
Joined: 14 Sep 2003 Posts: 473 Location: Čakovec
|
Posted: 03.12.2006 16:30 Post subject: |
|
|
Najjednostavnije sa npr. JQuery. Pa bi izgledalo ovako:
Code: | $("a[@rel=offsite]").addClass("exit"); |
|
_________________ We can exist in ambiguity, but it means the deepest loneliness. | creolab.hr | thefarewellreason.com |
|
Back to top |
|
|
nel`chee
Joined: 08 Jul 2004 Posts: 2087 Location: Rijeka
|
|
Back to top |
|
|
Sulien
Joined: 04 Jan 2004 Posts: 2905 Location: Zagreb
|
Posted: 03.12.2006 17:31 Post subject: |
|
|
Sve linkove dohvatiš sa document.links
Atribut dohvatiš direktno: link.rel |
|
|
Back to top |
|
|
nel`chee
Joined: 08 Jul 2004 Posts: 2087 Location: Rijeka
|
Posted: 03.12.2006 17:38 Post subject: |
|
|
ok i to bi onda izgledalo ovako?
Code: | function exitLinks() {
var exitLink=document.links;
for (var i = 0; i<exitLink.length; i++) {
if (exitLink[i].rel == "offsite") {
exitLink[i].className = 'exit';
}
}
}
} |
|
_________________ ♥ art & design portfolio ♥ free Photoshop brushes stuff ♥ sketchblog ♥ facebook ♥ |
|
Back to top |
|
|
strija
Joined: 14 Sep 2003 Posts: 473 Location: Čakovec
|
Posted: 04.12.2006 12:25 Post subject: |
|
|
Da JQuery je malo velik ako ti treba samo za ovo, ali je u jednoj liniji koda
Moze i ovako kao sto si zadnje napisala, trebalo bi raditi. |
_________________ We can exist in ambiguity, but it means the deepest loneliness. | creolab.hr | thefarewellreason.com |
|
Back to top |
|
|
|