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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:00:01+00:00 2026-05-16T16:00:01+00:00

I am working on a PHP document which has jQuery code in it. I

  • 0

I am working on a PHP document which has jQuery code in it. I am using a replaceWith() functions to strip outer divs and replace with span. it seems I can only replace it with <span> and not <span class="something">

Why is that?

Edit: Here is an example of the code:

Thanks Dave, but I actually use the second option in your code above, here is what I am trying to do:

$response[] = "jQuery('#myID').replaceWith('<span>'+jQuery('#myID').html()+'</span>');";

The above code works. Basically, I have an <a> element I want to replace with a <span> element and change the class on an ajax response.

Now, if I add classes to any of the spans above:, like this:

$response[] = "jQuery('#myID').replaceWith('<span class"something">'+jQuery('#myID').html()+'</span>');";

the code breaks, is it because of the outer double-quotes on the jQuery statement?

Edit

So it turned out to be an issue with my <a> element I was trying to replace, in addition to escaping the double-quotes around the class :). Thanks for the extremely prompt help. I am registering to give credit where credit is due 🙂

$response[] = "jQuery('#myID').replaceWith('<span class=\"something\">'+jQuery('#myID').html()+'</span>');";
  • 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-16T16:00:01+00:00Added an answer on May 16, 2026 at 4:00 pm

    Since the biggest change there is the addition of quotes, double check that the class attribute isn’t leaving an unterminated string open:

    // Broken:                 
    $("div").replaceWith("<span class="something">");
    
    // Fixed:
    $('div').replaceWith('<span class="something">');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

index.php has this jquery code which loads notifications.inc.php into a div on the page
I have a stupid question :) I'm working on a simple php document which
I am working on a webpage which has a comment box using which a
I've got an ASP document that 5 years old. Actually I'm working with PHP
I am working with php and want to have a page that has a
I'm working with php, jquery and fullcalendar ( http://arshaw.com/fullcalendar/ ) I've setted a function
I have a javascript file linked to a PHP page which has a value
Hello I have a php code which by echo calls the javascript function expand(txt)
I have a working code which allows users to insert url's into a database,
My DB has some text which is probably copied and pasted from word document

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.