javascript - need a solution to increase decrease font size on website -
i trying add option on 1 of website user can change font size. , found video on youtube (https://www.youtube.com/watch?v=mogbw3wkecc). don't know why script not working.
here codes:
<!doctype html> <html> <head> <title></title> <script type="text/javascript"> $(document).ready(function() { $('#fontincrease').click(function() { modifyfontsize('increase'); }); $('#fontdecrease').click(function() { modifyfontsize('decrease'); }); $('#fontreset').click(function() { modifyfontsize('reset'); }); function modifyfontsize(flag) { var divelement = $('#entrypbody'); var currentfontsize = parseint(divelement.css('font-size')); if (flag =='increase') { currentfontsize +=2; }; else if (flag ='decrease') { currentfontsize -=2; }; else currentfontsize = 15; divelement.css('font-size', currentfontsize); } }); </script> <style type="text/css"> .paragraph { font-size: 15px; } </style> </head> <body> <div> font size: <a id="fontincrease" href="#">increase</a> <a id="fontdecrease" href="#">decrease</a> <a id="fontreset" href="#">reset</a> </div> <div id="entrypbody" class="paragraph" > <ul> <li>unorderd list 1</li> <li>unorderd list 2</li> <li>unorderd list 3</li> <li>unorderd list 4</li> </ul> </div> </body> </html>
can 1 me out of problem??
there semi-colons in if statement. here way :
if (flag == 'increase') { currentfontsize +=2; } else if (flag == 'decrease') { currentfontsize -=2; } else { currentfontsize = 15; }
Comments
Post a Comment