I have a div which I would like to set custom dimensions using two text inputs.
<div id="theFrame"></div>
width: <input id="custWidth" type="text">
height: <input id="custHeight" type="text">
<br>
<button id="custSet">Set my width!</button>
I have tried setting the height and width with variables, but I am at a loss as to how to do it now.
var frame = $('div#theFrame');
$("#custWidth")
.keyup(function () {
var custWidth = $(this).attr('value');
})
.keyup();
$("#custHeight")
.keyup(function () {
var custHeight = $(this).attr('value');
})
.keyup();
$('#custSet')
.click( function() {
frame.css({height: custHeight, width: custWidth});
});
Thanks.
You most probably need to include ‘px’ when setting your CSS:
Also, you need to define your custHeight and custWidth parameters globally, since they are local only in the key up function.
And… I believe you don’t need the second keyup() call there: