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

  • Home
  • SEARCH
  • 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 6331107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:59:43+00:00 2026-05-24T17:59:43+00:00

I have html in a var that I am trying to edit. I want

  • 0

I have html in a var that I am trying to edit. I want to move the UL with class “files” to its own var then remove it from the data var.

I have this so far but doing it wrong. I cant seem to understand it.

var data = '<ul class="dirs"><li class="d"><a href="#" rel="/Games/">Games</a></li><liclass="d"><a href="#" rel="/Log/">Log</a></li></ul><ul class="files"><li class="f"><a href="#">fubar.txt</a></li><li class="f"><a href="#">fubar2.txt</a></li></ul>';

var files = $(data).find("UL.files").html();

Expected Result:

data = '<ul class="dirs"><li class="d"><a href="#" rel="/Games/">Games</a></li><li class="d"><a href="#" rel="/Log/">Log</a></li></ul>';

files = '<ul class="files"><li class="f"><a href="#">fubar.txt</a></li><li class="f"><a href="#">fubar2.txt</a></li></ul>';

Thanks

  • 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-24T17:59:44+00:00Added an answer on May 24, 2026 at 5:59 pm

    You can’t modify the string, but you can create new strings.

    var data = '<ul class="dirs"><li class="d"><a href="#" rel="/Games/">Games</a></li><liclass="d"><a href="#" rel="/Log/">Log</a></li></ul><ul class="files"><li class="f"><a href="#">fubar.txt</a></li><li class="f"><a href="#">fubar2.txt</a></li></ul>';
    
    var ul1 = $(data).filter('ul')[0];
    var ul2 = $(data).filter('ul')[1];
    
    var files1 = ul1.outerHTML || $('<div>').append(ul1).html();
    var files2 = ul2.outerHTML || $('<div>').append(ul2).html();
    

    This places a new UL element into ul1 and ul2. Then to get the html string, you use the .outerHTML property.

    Because Firefox doesn’t support outerHTML, you need a hack to make it browser compliant.

    Example output: http://jsfiddle.net/bjgLV/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some html extracted to a string var, and want to then use
I have a var that contains a full html page, including the head, html,
I have an html that has a link: <a id=myLink href=/aa.html title=New Bangoo class=bangoo>Bangoo</a>
I have the following HTML code: <fieldset> <legend><span>Contact Details</span> <span class=edit1>Edit</span><span class=hide1>Hide</span></legend> <div> <!--content-->
I have the following HTML (that is repeated many times) and want to get
If I have HTML content in a variable like so: var data = <div
I have a javascript array: var exclude = [Santorum,Obama,Romney,Gingrich]; I have html links: <a
I have the validation for autocomplete working. http://skoizumi.com/autocomplete/index.html var ac = $( #searchtext ).autocomplete({
I have a string contaning some html markup, like this: var html = <div>
I have this code <html> <include jquery> <script> function crea() { var html =

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.