5

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?

1
  • Where do you have this link element? In the header, ind the body? On StackOverflow it's good practice to add code that shows what you have tried and what error message you got or what other problem you got stuck. Commented May 29, 2015 at 13:22

1 Answer 1

4

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';
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.