Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7187549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:52:15+00:00 2026-05-28T18:52:15+00:00

Is there a way to replace, with Jquery, this: <ul class=sub-menu> <li><a href=#>Link</a></li> </ul>

  • 0

Is there a way to replace, with Jquery, this:

<ul class="sub-menu">
    <li><a href="#">Link</a></li>
</ul>

to this:

<div class="under">
    <p><a href="#">Link</a></p>
</ul>

Parent element is: <ul id="menu">

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:52:16+00:00Added an answer on May 28, 2026 at 6:52 pm

    You could unwrap the a element and then wrap it in the new elements:

    $(".sub-menu").find("a").unwrap().unwrap().wrap("<div class='under'>").wrap("<p>");
    

    The two calls to unwrap remove the li and then the ul, and the two calls to wrap add the div and the p. Note that we have to wrap the div first, then the p.

    Here’s a working example (inspect the DOM in the results window to see what you end up with).

    Note that I’m assuming the closing ul was meant to be a closing div tag in your second example!

    Edit

    You could also combine the two calls to wrap, which should be faster:

    $(".sub-menu").find("a").unwrap().unwrap().wrap("<div class='under'><p></p></div>");
    

    Another edit

    Using unwrap twice seemed a little messy to me. Now that I’ve had a little spare time I’ve thrown together a simple plugin that allows you to unwrap multiple ancestor elements from a target element. I’ve called it unwrapUntil, and you can find it on GitHub. It will work for any number of unwraps, and using it in this specific case would probably be a bit extreme, but it would allow us to do the following:

    $(".sub-menu").find("a").unwrapUntil(2).wrap("<div class='under'><p></p></div>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way in jQuery to replace only the textNode of an element
I'm using Jquery for menu created like: <div class=prof_info1>home</div><div class=prof_info2>info2</div><div class=prof_info3>info3</div> And Jquery code
Is there an way to delete everything after a particular div with javascript/jquery and
Is there any way to replace a content using jQuery from - let's say,
Is there a way to replace the following code with some JQuery code that
I have html code like this: <li> <a href=''>Example</a>&nbsp;<a href='' class='sub'>Edit</a>&nbsp;<a href='' class='sub'>Delete</a> </li>
Is there any way to replace titles faster then str_replace function? I've got a
Is there a way to run a regexp-string replace on the current line in
is there any best practice way to replace a part of the default template.
Is there a way to search and eventually search and replace text in Visual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.