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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:30:55+00:00 2026-05-21T15:30:55+00:00

Newbie in javascript.. Need a little help. I have a SPAN or IMG that

  • 0

Newbie in javascript.. Need a little help.

I have a SPAN or IMG that I want to fadeOut using javascript. However nothing happens when I do this:

// HTML
<span id='test_one'>Span Text Here</span>
<img src='img_src_here' id='test_two'>

// JavaScript
$(test_one).fadeOut();
$(test_two).fadeOut();

But if I do this, it functions correctly:

// HTML
<div id='test_one'>Span Text Here</div>

// JavaScript
$(test_one).fadeOut();

Am I just making or a silly mistake or am I going insane?

Thanks
Coulton

  • 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-21T15:30:56+00:00Added an answer on May 21, 2026 at 3:30 pm

    Assuming you’re using jQuery, your selector is incorrect:

    $('#test_one').fadeOut();
    

    Note that it should be a string (so single or double quotes) and use ‘#’ to select by id. Documentation of selectors can be found on the jQuery site.

    This should work:

    // HTML
    <span id='test_one'>Span Text Here</span>
    <img src='img_src_here' id='test_two'>
    
    // JavaScript
    $('#test_one').fadeOut();
    $('#test_two').fadeOut();
    

    Edit

    As to why it works with the div but not the img or span, I’m not entirely clear but as @Steve pointed out, it is possible to reference elements by using their ids as global variables. However, this is non-standard behaviour and only some browsers (notoriously IE) perform this mapping of element ids to the global namespace. IE also allows fetching of named elements via getElementById()! See this and this. I would suggest not depending on this behaviour.

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

Sidebar

Related Questions

Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
Java Newbie here. I have a JFrame that I added to my netbeans project,
am totally new to Javascript , but i need it for using googlemaps in
A newbie question from me, please. I have a large data set that I
.NET newbie here... I'd like to make a button in a Windows form that
I'm a newbie to pgsql. I have few questionss on it: 1) I know
Say I have a web service http://www.example.com/webservice.pl?q=google which returns text google.com. I need to
Totally newbie about JS. I need to use an external script which modifies some
i am a newbie on web development, so i have some problems first of
Newbie to LINQ, and trying to write the following query... select f.Section_ID, f.Page_ID, f.SortOrder,

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.