简体   繁体   中英

How can I wrap the element with div container if it not wrap up with?

I tried to wrap the following element with div container, if it is not wrap up with.

<p class="fileDetails"><div class="filename">text goes here</div><div class="fileSize">text goes here</div></p>

How to fix this?

You can't put <div> elements inside of <p> s. (Down to the specs -- see also Putting <div> inside <p> is adding an extra <p> ) if you're interested.

So you'll have to switch to a <span> that's styled the way you want, or probably semantically an unordered list makes more sense.

Here's a fiddle showing how it could work.

Working Example: http://jsfiddle.net/ef43tgto/

You should make .filename and .fileSize <p> tags and the .fileDetails a <div> . Then you can use jQuery .wrap()

<div class="fileDetails">
    <p class="filename">text goes here</p>
    <p class="fileSize">text goes here</p>
</div>

if ( !$('.container').length ) {
    $('.fileDetails').wrap('<div class="container" />')
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM