Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change the href of a css link via jquery

Tags:

html

jquery

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

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

like image 449
Omu Avatar asked Nov 28 '22 04:11

Omu


2 Answers

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

have fun

like image 99
Hannes Avatar answered Dec 09 '22 17:12

Hannes


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");
});​
like image 39
Lasse Espeholt Avatar answered Dec 09 '22 19:12

Lasse Espeholt