-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChangeStyleOfText.html
67 lines (50 loc) · 1.29 KB
/
ChangeStyleOfText.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!--Write a Javascript (JS) function changeAll() that restyles all numbers in a specified DIV
element containing some text when a button is clicked by the user. The restyling should
underline all numbers, for example, “There are 7 words in this sentence!” would be changed
to “There are 7(underline) words in this sentence!”. Please provide the HTML code for the button that
is used to invoke changeAll(). -->
<!DOCTYPE html>
<html>
<head>
<style type="text/CSS">
body{
font-family:Times New Roman;
font-size:15px;
}
textarea {
font-family:Times New Roman;
font-size:15px;
border:2px solid black;
width: 300px;
height: 217px;
padding:10px;
}
span{
text-decoration: underline;
}
button{
text-align: center;
width: 100px;
}
</style>
<script>
function underlineNumbers(){
var szukane = document.getElementById("input").innerHTML;
var look = "123456789";
var wyswietl="";
for(i=0; i<szukane.length; i++)
{
if(szukane.charAt(i).match(/^\d+$/))
{ wyswietl= wyswietl+"<span>"+szukane.charAt(i)+"</span>";}
else{wyswietl= wyswietl+szukane.charAt(i);}
}
document.getElementById("input").innerHTML = wyswietl;
}
</script>
</head>
<body>
<div id="input">
34222 is a truth 3 </div>
<button onClick="underlineNumbers()">underNum</button>
</body>
</html>