开发者

change the href of a css link via jquery

<head>
<link href="foo.css" rel="stylesheet" type="text/css" />
&l开发者_运维知识库t;/head>

can I via jquery change the href of this link from foo.css to bar.css


$('link[href="foo.css"]').attr('href','bar.css');

have fun


Html:

<head>
<link id="test" href="foo.css" rel="stylesheet" type="text/css" />
</head>
<body>
    ...
</body>​​​​​​​​​​

And the jQuery:

​$(document).ready(function() {
    $("#test").attr("href", "bar.css");
});​


And one more

Html:

<head> 
<link id="bar" href="foo.css" rel="stylesheet" type="text/css"/> 
</head>

jQuery:

$("link[id='bar']").attr('href', 'bar.css');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜