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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:09:17+00:00 2026-05-24T05:09:17+00:00

Hi there Stack Overflow, I’m new at learning jQuery and just trying to condense

  • 0

Hi there Stack Overflow,

I’m new at learning jQuery and just trying to condense some sample code down, how would I go about the following.

On mouseover of #navweb, select all elements with a class of .web and then change the background of each of these elements to url(back/”+ i +”.png) where i is the JS loop, and then fadeIn these new backgrounds.

Here’s the JS i have at current which works (except for the fadeIn)

function showweb() {
for(var i=1; i < 45; i++){
var el = document.getElementById("im"+(i));
if(el && /web/.test( (el ||{}).className)){
  el.style.backgroundImage = "url(back/"+ i +"col.png)";}
}
}

function hideweb() {
for(var i=1; i < 45; i++){
    var el = document.getElementById("im"+(i));
    if(el && /web/.test( (el ||{}).className)){
      el.style.backgroundImage = "url(back/"+ i +".png)";}
    }
}

I started and got to something like this but it doesn’t work, becasue i know its not complete, can you use counters in jQuery?

$('#navweb').mouseover(function(){

var i = 1;
$(".web").each(function(){
$(this).css('background-image', 'url(back/" + i + ".col.png)'); 
i += 1;
});

});

Many thanks to all replies.

EDIT:
Thanks to all replies, Guffa’s proved the most ideal and condensed for my use; I have also added the fadeIn() method but doesn’t seem to be triggering on the mouseover?

$('#navweb').mouseover(function(){

  $(".web").each(function(){
    var i = parseInt(this.id.substr(2));
    $(this).css('background-image', 'url(back/' + i + 'col.png)').fadeIn(1000); 
  });

});
  • 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-24T05:09:18+00:00Added an answer on May 24, 2026 at 5:09 am

    You can get the number from the id of the element:

    $('#navweb').mouseover(function(){
    
      $(".web").each(function(){
        var i = parseInt(this.id.substr(2));
        $(this).css('background-image', 'url(back/' + i + '.col.png)'); 
      });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some basic CMS functionality with rich text editing. On stack overflow there
I've just found out about Stack Overflow and I'm just checking if there are
There are some threads on Stack Overflow dealing with implementing priority queues in .Net
JQuery is a hot topic these days. Today, on Stack Overflow, there are currently
Hello there people of stack overflow, I have just started developing with android and
From this answer in stack overflow and the sample project referred there, i got
There are some topics on Stack Overflow on the compiler error Cannot refer to
There are already some pretty good threads on this topic on Stack Overflow, but
There is a new badge on Stack Overflow. The woot badge is awarded to
When you get a badge or aren't logged in to stack overflow there's a

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.