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
)
ps 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 :
ps 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 ?
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
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'
}));
});
Change it to this:
$(".btn").on('click',function (){
$(".myTextArea").attr('class', 'msgAbsWrap');
});
jsbin: http://jsbin.com/izopaz/12/
Do it like this:
$(".btn").on('click',function (){
$(".myTextArea").wrap($('<div></div>', {
"class": 'msgAbsWrap',
"style": "position:relative;"
}));
});
Check this example: jsbin
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.