Reputation: 148744
I have a simple TextArea and a button
When the button is clicked , I need to wrap
(exactly) the text area with a red div (border:solid 1px red
)
p.s this wrapper div must be position:relative
because I need to add future absolute positioned elements
And so I wrote this code :
$(".btn").on('click',function (){
$(".myTextArea").wrap($('<span/>', {
"class": 'msgAbsWrap',
"style": "position:relative;display:inline" /*it's inline by default ,I know*/
}));
});
but the problem is that it doesn't wrap it as it should :
p.s. Im using chrome v 26.
(my bad) I forgot to remove the width from the textArea (after 1000 testings). it should be width:100%
. can you please try now ?
Upvotes: 0
Views: 72
Reputation: 74748
You can do these changes to take effects:
.msgAbsWrap {
border:solid 1px red;
display:inline-block;
width:100%;
position:relative;
}
$(".btn").on('click', function () {
$(".myTextArea").wrap($('<span/>', {
"class": 'msgAbsWrap'
}));
});
Upvotes: 1
Reputation: 388446
Change the display style of the span to display: inline-block;
$(".myTextArea").wrap($('<span/>', {
"class": 'msgAbsWrap',
"style": "position:relative; display:inline-block; width: 100%;"
}));
Demo: JSBIN
Upvotes: 1
Reputation: 3990
Do it like this:
$(".btn").on('click',function (){
$(".myTextArea").wrap($('<div></div>', {
"class": 'msgAbsWrap',
"style": "position:relative;"
}));
});
Check this example: jsbin
Upvotes: 0
Reputation: 820
Change it to this:
$(".btn").on('click',function (){
$(".myTextArea").attr('class', 'msgAbsWrap');
});
jsbin: http://jsbin.com/izopaz/12/
Upvotes: 0