views:

339

answers:

3

hi, i have 4 links and i need to change the href attribute in a rel attribute. i know i cannot do it so i'm trying to get the data from the href attribute, setting a new attribute (rel), inserting the data inside it and then removing the href attibute.

basically i'm doing this:

$('div#menu ul li a').each(function(){
        var lin = $(this).attr('href');
        $('div#menu ul li a').attr('rel',lin);
        $(this).removeAttr('href');


        })
    })

it works but it sets the same rel data in every link i have.

any help?

thnx

+1  A: 

Try

$('div#menu ul li a').each(function(){
    var lin = $(this).attr('href');
    $(this).attr('rel',lin);
    $(this).removeAttr('href');


    })
})

Haven't actually ran the code...but that looks like it should do the trick.

E-man
looks like I've been beaten! +1 to you.
David Murdoch
A: 

Change:

$('div#menu ul li a').attr('rel',lin);

To:

$(this).attr('rel',lin);
awgy
perfect! thnx :)
junray
A: 

You are probably doing "it" wrong. (meaning there is a better way to do what you are attempting).

but to just answer your question:

$('#menu ul li a').each(function(){
    var lin = $(this).attr('href');
    $(this).attr('rel',lin).removeAttr('href');
});
David Murdoch