+ 4
How to change css file using js?
Is it possible to modify head section, for example a source of CSS file by using JavaScript?
4 Antworten
+ 4
i recommend you jQuery. It makes this very easy.
$(".your-class").css("color", "red");
$("#your-id").css("position", "absolute");
$("h1").css("font-size", 40);
You can edit css like this with jQuery. And you can do much more.
+ 4
Thanks guys, you helped me a lot :)
+ 2
as Mahmus Ozgur said, use jQuery. if you want to add more than one style, put them in a class in css file and the use addClass() function. it will be easier. there is also removeClass function to change your styles.
+ 1
try this;
var elements = document.getElementsByTagName('link');
var oldUrl = 'a'; //url to replace
var newUrl = 'b' //url that replace the old url
for(var i = 0; i<elements.length; i++){
if(elements[i].href == oldUrl){
elements.href = newUrl;
}
}