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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:41:19+00:00 2026-05-26T07:41:19+00:00

I create a span with a global variable like this: var $span = jQuery(‘<span></span’);

  • 0

I create a span with a global variable like this:

var $span = jQuery('<span></span');
jQuery($span).append('<img src="myimage.gif"/>'); 
jQuery($span).insertAfter('#username');

It works but I would like to remove the span in some part of my code.
I try with:

$span.remove();

but it doesn’t work.

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-26T07:41:20+00:00Added an answer on May 26, 2026 at 7:41 am

    You really need to post the full code for questions like this. It makes it really difficult for people to help you if they can’t see what you’re doing in context.

    That said, if $span.remove() does not remove the <span>, then plainly and simply $span is not referencing what you think it is. Either it’s another element or it’s undefined.

    Where are you making it a “global” variable (bad idea by the way)? In javascript there really isn’t such a thing as a true global variable — they are only defined for for the context they are in. If the immediate context is your document (i.e. <script>var myVar = 'foo';</script>), that’s for all intents and purposes a “global” variable, but anything else is a “local” variable.

    Basically, use console.log or similar to introspect the value of $span in the place where you’re trying to utilize it. If it’s undefined (which my best guess is that it is), then figure out why it’s not defined in the context your working in.

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

Sidebar

Related Questions

I create HTML snippet on-the-fly: $('<span/>').addClass(spanClass) Is there a jQuery way to wrap this
I wanna create some loading dots, like this: At 0000 miliseconds the span content
I'm trying to create a button with icon like this : HTML: <div id='button'>
I have some jQuery code like this: // Called right away after someone clicks
i would like to create the span class error, and fade it if(formName ==
I have create a jquery to convert title attribute of input to span with
I would like to create the following: And I did as follows: <span>* Primary
I need to create an element from this html string: <li class=station_li> <span class=seq_num></span>
I am trying to create a horizontal menu with the elements represented by <span>
I don't get it. I created this regular expression: <span class=copy[Green|Red].*>[\s]*(.*)[\s]*<\/span> to match certain

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.