How to change CSS stylesheet using a dart?

I am working on a project for an exam and I need to change the name of the stylesheet on the page. How can I do this with Darth? I saw that I can edit every attribute of my css from Dart, but I have already made other css that I would like to use on 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 do this

<link href="stile-blu.css" rel="stylesheet" type="text/css">

How can i do this?

+4
source share
1 answer

Assuming your item <link ...>is in an item<head>

document.querySelector('#button').onClick.listen((_) {
  var stile = document.head.querySelector('link[href="stile.css"]');
  stile.attributes['href'] = 'stile-blu.css';
});

If you add an attribute idto the 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';
});
+3
source

All Articles