Skip to content

Instantly share code, notes, and snippets.

@pratikbutani
Last active March 7, 2023 17:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pratikbutani/de00ad7637984e509d2eff05ef910887 to your computer and use it in GitHub Desktop.
Save pratikbutani/de00ad7637984e509d2eff05ef910887 to your computer and use it in GitHub Desktop.
Dart with HTML & CSS

Dart with HTML & CSS

Created with <3 with dartpad.dev.

<html>
<head>
<meta charset="UTF-8">
<title>Dart + HTML + CSS Example</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>Click the button to change the color of the text!</h1>
<br><br>
<button id="colorButton">Change color</button>
</body>
</html>
import 'dart:html';
void main() {
var colorButton = querySelector('#colorButton');
var h1 = querySelector('h1');
var colors = ['red', 'green', 'blue'];
var currentColorIndex = 0;
colorButton?.onClick.listen((event) {
h1?.style.color = colors[currentColorIndex];
currentColorIndex = (currentColorIndex + 1) % colors.length;
});
}
h1 {
color: black;
}
body {
font-family: sans-serif;
text-align: center;
margin-top: 50px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment