Trying to create a button to change font size, Trying to create a button to change my font size using html and js |
Trying to create a button to change font size, Trying to create a button to change my font size using html and js |
markee |
Nov 1 2021, 11:09 PM
Post
#1
|
Group: Members Posts: 4 Joined: 4-October 21 Member No.: 28,131 |
Hi, I'm not sure if I'm posting this in the correct place. I am trying to create a button that allows a user to increase the font size and decrease the font size of a page. I'm am doing this with an HTML page and a javascript page, which I have never done before.
This is what I have at the beginning of the body section on my HTML page: <section> <p class=''>Change the font size below</p> <button class="increase">+</button> <button class="decrease">-</button> </section> I also have this at the end of my body section: <script src="main.js"></script> This is what my entire javascript page consists of: $(document).ready(function () { var changing_font_size = new Array(".change"); changing_font_size = changing_font_size.join(","); $(".decrease").click(function () { let originalFontSize = $(changing_font_size).css("font-size"); let changed_sized = parseFloat(originalFontSize, 10) - 0.8; $(changing_font_size).css("font-size", changed_sized); }); $(".increase").click(function () { let originalFontSize = $(changing_font_size).css("font-size"); let changed_sized = parseFloat(originalFontSize, 10) + 0.8; $(changing_font_size).css("font-size", changed_sized); }); }); If anyone knows why nothing happens when I click these buttons please help |
Lo-Fi Version | Time is now: 7th June 2024 - 08:26 AM |