1

I want to add some html to a widget area, basically to wrap the inner content. Here is the current code:

<aside id="meta-2" class="widget widget_meta"><h1 class="widget-title">Stuff</h1>
  <ul>
    <li><a href="#">Log in</a></li>
    <li><a href="#">Entries <abbr title="Really Simple Syndication">RSS</abbr></a></li>
    <li><a href="#">Comments <abbr title="Really Simple Syndication">RSS</abbr></a></li>
  </ul>
</aside>

I want it to become:

<aside id="meta-2" class="widget widget_meta"><h1 class="widget-title">Stuff</h1>
 <div class="widget-inner">
  <ul>
    <li><a href="#">Log in</a></li>
    <li><a href="#">Entries <abbr title="Really Simple Syndication">RSS</abbr></a></li>
    <li><a href="#">Comments <abbr title="Really Simple Syndication">RSS</abbr></a></li>
  </ul>
 </div>
</aside>

Please note that some 'widgets' don't contain a UL, there might just be an image inside or some text.

I have tried some jQuery snippets using before, append etc but to no avail.

Any help would be most appreciated.

3 Answers 3

4

You can use .wrap():

$( "aside ul" ).wrap( "<div class='widget-inner'></div>" );

Working Demo

Update: for non uniform DOM:

$( "aside h1" ).nextAll().wrap( "<div class='widget-inner'></div>" );

Working Demo

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I have updated my question above as I didn't explain it well. Some widgets won't have a UL inside them, some maybe just text or an image for example.
@HuwRowlands: what about h tag. is it going to be always there??
Yes, H1 will always be there.
0

use .wrap() function see link : wrap() jquery

Comments

0

Answer from above was:

$( "aside h1" ).nextAll().wrap( "<div class='widget-inner'></div>" );

Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.