I'm working on a project for an exam and I need to change the stylesheet's name in the page. How can I do this with Dart? I've seen that I can edit every attribute of my css from Dart but I've already made others css that I would like to use in my page. For example, I have this in my html page:
<link href="stile.css" rel="stylesheet" type="text/css">
I need to edit the page to make this
<link href="stile-blu.css" rel="stylesheet" type="text/css">
How can I do this?
Assuming your <link ...>
element is in the <head>
element
document.querySelector('#button').onClick.listen((_) {
var stile = document.head.querySelector('link[href="stile.css"]');
stile.attributes['href'] = 'stile-blu.css';
});
If you add an id
attribute to your link element the selector can be simplified
<link id="mystyle" href="stile.css" rel="stylesheet" type="text/css">
document.querySelector('#button').onClick.listen((_) {
var stile = document.head.querySelector('#mystyle');
stile.attributes['href'] = 'stile-blu.css';
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With