-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathplaceholder-shown.html
More file actions
34 lines (30 loc) · 1.06 KB
/
placeholder-shown.html
File metadata and controls
34 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html>
<title>CSS Selectors Test: :placeholder-shown invalidation</title>
<link rel="help" href="https://un5n798jx6qx6j0rmf2verhh.julianrbryant.com/selectors/#placeholder">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#target { color: red; }
input:placeholder-shown + #target { color: green; }
</style>
<input id="input" type="text">
<span id="target"></span>
<script>
const red = "rgb(255, 0, 0)";
const green = "rgb(0, 128, 0)";
test(() => {
assert_equals(getComputedStyle(target).color, red);
}, "Initially no placeholder text");
test(() => {
input.setAttribute("placeholder", "PLACEHOLDER");
assert_equals(getComputedStyle(target).color, green);
}, "Added placeholder text");
test(() => {
input.setAttribute("placeholder", "");
assert_equals(getComputedStyle(target).color, green);
}, "Set placeholder text to empty string");
test(() => {
input.removeAttribute("placeholder");
assert_equals(getComputedStyle(target).color, red);
}, "Removed placeholder attribute");
</script>