jquery更改属性 [英] jquery change attribute

查看:152
本文介绍了jquery更改属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个链接,我需要更改rel属性中的href属性。
i知道我不能这样做所以我试图从href属性获取数据,设置一个新属性(rel),在其中插入数据然后删除href attibute。

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.

基本上我这样做:

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


        })
    })

它可以工作,但它在我拥有的每个链接中设置相同的rel数据。

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

任何帮助?

推荐答案

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

这篇关于jquery更改属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆