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 7446487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:19:45+00:00 2026-05-29T12:19:45+00:00

Is it possible to shorten these jQuery snippets by chaining them together? For the

  • 0

Is it possible to shorten these jQuery snippets by chaining them together? For the second chain, I’d like to get rid of the w class if possible.

$('#content').prepend("<h1 />");
$('#content h1').append( $('#content>p:first strong').html() );
$('#content>p:first strong').parent().remove();

$('font').wrapInner('<p class="w"/>');
$("p.w").unwrap().unwrap();

Edit: Let me clarify my second jQuery snippet. I’m cleaning up old HTML markup that looks like this:

<div id="content">
    <p>
        <font>
            <b>Sample Title</b>
            <br>
            More sample text.
        </font>
    </p>
</div>

And changing it to this:

<div id="content">
    <p>
        <b>Sample Title</b>
        <br>
        More sample text.
    </p>
</div>
  • 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-29T12:19:46+00:00Added an answer on May 29, 2026 at 12:19 pm

    This is how I would do it:

    var content = $( '#content' )[0];
    var para1 = $( content ).children( 'p' )[0];
    var text = $( para1 ).children( 'strong' ).text();
    
    $( '<h1>', { text: text }).prependTo( content );
    $( para1 ).remove();
    

    As of jQuery 1.4, the second argument to jQuery() can accept a map
    consisting of a superset of the properties that can be passed to the
    .attr() method. Furthermore, any event type can be passed in, and the
    following jQuery methods can be called: val, css, html, text, data,
    width, height, or offset. The name “class” must be quoted in the map
    since it is a JavaScript reserved word, and “className” cannot be used
    since it is not the correct attribute name.

    From the docs: http://api.jquery.com/jQuery/#jQuery2

    So, you can pass an object literal as the second argument. That object literal “initializes” the newly created DOM element (the H1 element in our case).

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

Sidebar

Related Questions

Possible Duplicate: Shorten String in PHP (full words only) How to get first x
I have an application with URLs such as these: https://www.domain.com/example/public/subscription https://www.domain.com/example/public/subscription/source https://www.domain.com/example/public/test/subscription I'd like
Possible Duplicate Why can't I have a non-integral static const member in a class?
Influenced by jQuery, I'm experimenting with method chaining in javascript. I constructed a wrapper
Is this possible? If so, I can't seem to get the syntax right. (C++
Looking at this get value of inside a tag with jQuery.? <span> <b>hi_1</b> <b>hi_2</b>
Possible Duplicate: C++ templates that accept only certain types For example, if we want
Possible Duplicate: css rule to disable text selection highlighting On my homepage i have
Possible Duplicate: How to: URL re-writing in PHP? How can a website use an
Possible Duplicate: XPath: How to match attributes that contain a certain string I'm trying

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.