Say I have:
<input type="text" name="changefont" value="16">
How do I change a certain node's font-size
(for example a paragraph) based on keyup
when user types in the value of the font they want?
So far I thought it would be this, but I guess not:
$('input[name="changefont"]').bind("keyup", function(){
var fontSize = $(this).val();
$('p').css('font-size', fontSize);
});
Aside from the selector typo, you need to add a unit in addition to the inputs value:
$('input[name="changefont"]').bind("keyup", function() {
var fontSize = $(this).val();
$('p').css('font-size', fontSize + "px");
});
I also recommend using .on()
in place of .bind()
especially if you're using ver. 1.7+
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.