1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < title > Change Font using javascript</ title >
5
+ <!-- Required meta tags -->
6
+ < meta charset ="utf-8 ">
7
+ < meta name ="viewport " content ="width=device-width, initial-scale=1, shrink-to-fit=no ">
8
+ < link rel ="stylesheet " href ="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css " />
9
+ </ head >
10
+
11
+ < body >
12
+ < div class ="container ">
13
+ < h2 class ="text-center "> Change Font using javascript</ h2 >
14
+ < div class ="row form-group ">
15
+ < div class ="col-md-8 m-auto ">
16
+ < div class ="row ">
17
+ < div class ="col-md-4 fontstyle ">
18
+ </ div >
19
+ < div class ="col-md-4 fontsize ">
20
+ </ div >
21
+ < div class ="col-md-4 fontweight ">
22
+ </ div >
23
+ </ div >
24
+ </ div >
25
+ </ div >
26
+ HTML isn't computer code
27
+ < p > HTML isn't computer code, but is a language that uses US English to enable texts (words, images, sounds) to
28
+ be inserted and formatting such as colo(u)r and centre/ering to be written in. The process is fairly simple;
29
+ the main difficulties often lie in small mistakes - if you slip up while word processing your reader may
30
+ pick up your typos, but the page will still be legible. However, if your HTML is inaccurate the page may not
31
+ appear - writing web pages is, at the least, very good practice for proof reading!</ p >
32
+ < p > Learning HTML will enable you to:</ p >
33
+ < ul >
34
+ < li > create your own simple pages</ li >
35
+ < li > read and appreciate pages created by others</ li >
36
+ < li > develop an understanding of the creative and literary implications of web-texts</ li >
37
+ < li > have the confidence to branch out into more complex web design</ li >
38
+ </ ul >
39
+ < h1 > Enter the main heading, usually the same as the title.</ h1 >
40
+ < p > Be < b > bold</ b > in stating your key points. Put them in a list: </ p >
41
+ < ul >
42
+ < li > The first item in your list</ li >
43
+ < li > The second item; < i > italicize</ i > key words</ li >
44
+ </ ul >
45
+ < p > Improve your image by including an image. </ p >
46
+ < p > Add a link to your favorite < a href ="https://www.dummies.com/ "> Web site</ a > .
47
+ Break up your page with a horizontal rule or two. </ p >
48
+ < hr >
49
+ < p > © Wiley Publishing, 2011</ p >
50
+ </ div >
51
+ < script >
52
+ let fontStyles = [ 'normal' , 'italic' , 'oblique' ] ;
53
+ let fontWeights = [ 'normal' , 'bold' , 'bolder' ] ;
54
+ let fontSizes = [ 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 ] ;
55
+
56
+ // Create Fontstyle select box
57
+ let fontStyleLabel = document . createElement ( "label" ) ;
58
+ fontStyleLabel . textContent = 'Font Style' ;
59
+ document . querySelector ( '.fontstyle' ) . appendChild ( fontStyleLabel ) ;
60
+ let fontStyleSelect = document . createElement ( "select" ) ;
61
+ fontStyleSelect . setAttribute ( 'class' , 'style form-control' ) ;
62
+ for ( let i = 0 ; i < fontStyles . length ; i ++ ) {
63
+ let el = document . createElement ( "option" ) ;
64
+ el . textContent = fontStyles [ i ] ;
65
+ el . value = fontStyles [ i ] ;
66
+ fontStyleSelect . appendChild ( el ) ;
67
+ }
68
+ document . querySelector ( '.fontstyle' ) . appendChild ( fontStyleSelect ) ;
69
+ document . querySelector ( '.style' ) . onchange = ( ele ) => {
70
+ document . body . style . fontStyle = ele . target . value ;
71
+ }
72
+
73
+ // Create Fontweight select box
74
+ let fontWeightLabel = document . createElement ( "label" ) ;
75
+ fontWeightLabel . textContent = 'Font Weight' ;
76
+ document . querySelector ( '.fontweight' ) . appendChild ( fontWeightLabel ) ;
77
+ let fontWeightSelect = document . createElement ( "select" ) ;
78
+ fontWeightSelect . setAttribute ( 'class' , 'weight form-control' ) ;
79
+ for ( let i = 0 ; i < fontWeights . length ; i ++ ) {
80
+ let el = document . createElement ( "option" ) ;
81
+ el . textContent = fontWeights [ i ] ;
82
+ el . value = fontWeights [ i ] ;
83
+ fontWeightSelect . appendChild ( el ) ;
84
+ }
85
+ document . querySelector ( '.fontweight' ) . appendChild ( fontWeightSelect ) ;
86
+ document . querySelector ( '.weight' ) . onchange = ( ele ) => {
87
+ document . body . style . fontWeight = ele . target . value ;
88
+ }
89
+
90
+ // Create Fontsize select box
91
+ let fontSizeLabel = document . createElement ( "label" ) ;
92
+ fontSizeLabel . textContent = 'Font Size' ;
93
+ document . querySelector ( '.fontsize' ) . appendChild ( fontSizeLabel ) ;
94
+ let fontSizeSelect = document . createElement ( "select" ) ;
95
+ fontSizeSelect . setAttribute ( 'class' , 'size form-control' ) ;
96
+ for ( let i = 0 ; i < fontSizes . length ; i ++ ) {
97
+ let el = document . createElement ( "option" ) ;
98
+ el . textContent = fontSizes [ i ] + 'px' ;
99
+ el . value = fontSizes [ i ] ;
100
+ fontSizeSelect . appendChild ( el ) ;
101
+ }
102
+ document . querySelector ( '.fontsize' ) . appendChild ( fontSizeSelect ) ;
103
+ document . querySelector ( '.size' ) . onchange = ( ele ) => {
104
+ document . body . style . fontSize = ele . target . value + 'px' ;
105
+ }
106
+ </ script >
107
+ </ body >
108
+ </ html >
0 commit comments