简体   繁体   中英

Dynamically change font-family and font-size

I want to change the fonts and size of the text dynamically

but I don't see any answer in the browser and also no errors in my code this is demo

html:

<body>
<form id="texteditor">
    <select id="font">
        <option value="School">School</option>
        <option value="SansitaOne">SansitaOne</option>
        <option value="oliver">oliver</option>
        <option value="JuraLight">Jura-Light-webfont</option>
        <option value="Jura">Jura-DemiBold-webfont</option>
        <option value="DJGROSS">DJGROSS-webfont</option>
        <option value="College">College</option>
        <option value="BYekan">BYekan</option>
        <option value="BRoya">BRoya</option>
        <option value="BMitraBold">BMitraBold</option>
        <option value="BMitra">BMitra</option>
    </select>
    <select id="size">
        <option value="7">7</option>
        <option value="10">10</option>
        <option value="15">15</option>
        <option value="17">17</option>
        <option value="20">20</option>
    </select>
</form>
<textarea class="changeme">this is my text example !!!</textarea>
</body>

jquery :

$("#font").change(function() {
//alert($(this).val());
$('.changeMe').css("font-family", $(this).val());

  });



 $("#size").change(function() {
 $('.changeMe').css("font-size", $(this).val() + "px");
 });

Aside from not including jQuery in the example, you had a typo.

$('.changeMe') should be $('.changeme')

UPDATED EXAMPLE HERE

$("#font").change(function() {
    $('.changeme').css("font-family", $(this).val());

});

$("#size").change(function() {
    $('.changeme').css("font-size", $(this).val() + "px");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM