开发者

change the href of a css link via jquery

开发者 https://www.devze.com 2023-01-18 00:30 出处:网络
<head> <link href=\"foo.css\" rel=\"stylesheet\" type=\"text/css\" /> &l开发者_运维知识库t;/head>
<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

精彩评论

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