From your comments I've understood you'd like to set the font-size
in the textarea
to same size as h1
tag would have.
Since there's no h1
tag in your HTML, you need to create a one in the click event handler function of the #nowBtn
:
var header = document.createElement('h1'),
size = window.getComputedStyle(header, null).fontSize;
Then you can set the font-size
of textarea
like this:
$('textarea').css('font-size', size);
A live demo at jsFiddle.
EDIT
As bfavaretto has mentioned, a cross-browser way would be to use jQuery to get the size of the h1
:
size = $(header).css('font-size')
Have a look at this fiddle - it might be what you want.
http://jsfiddle.net/Nj7pj/
$(document).ready(function () {
$('.btn-primary').on('click', function () {
inputVal = $('#getString').val();
newTextAreaVal = "<h1>" + inputVal + "</h1>";
$('textarea').val(newTextAreaVal);
});
});
I think you can do
var h1 = $("h1.classYouWant");
$(".form-control").val( "<h1>" + h1.text() + "</h1>" );
if is dynamic the header (h1 or h2 or h3 )
you can do
var header = $(".classYouWant").get(0);
$(".form-control").val( header.outerHTML );
Post a Comment for "How To Get The Value With Getelementbyid In A Class And Use It In A Different Class"