Skip to content Skip to sidebar Skip to footer

Change The Href Of A Css Link Via Jquery

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

Solution 1:

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

have fun

Solution 2:

Html:

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

And the jQuery:

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

Solution 3:

And one more

Html:

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

jQuery:

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

Post a Comment for "Change The Href Of A Css Link Via Jquery"