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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:45:48+00:00 2026-05-26T05:45:48+00:00

I wrote those simple lines in order to show an .elemproduct div only if

  • 0

I wrote those simple lines in order to show an .elemproduct div only if it has a background-image set.

I developed under Chrome and just realised that this code is only working under Webkit browsers. When failing, it shows up every .elemproduct as if the if statement was not recognized.

function hideBox() {
  var $bg = $('.elemproduct');

  $bg.each(function() { 
     if ($(this).css("background-image") === "url(####)") {   
        return true; 
     }
     else {
        $(this).show();
     }
  });

  return true;
};

Any ideas ?

  • 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-26T05:45:48+00:00Added an answer on May 26, 2026 at 5:45 am

    I’d suggest that it might be because the background-image is never going to be exactly equal (===) to the path of the (presumably) image directory http://www.infiniscale.com/beta/.

    If you want to simply hide those .elemproduct elements without a background-image it seems a little easier to use:

    function hideBox() {
        var $eP = $('.elemproduct');
        $eP.each(
    
        function() {
            if (!$(this).css('background-image') || $(this).css('background-image') == 'none') {
                $(this).hide();
            }
        });
    }
    
    hideBox();
    

    JS Fiddle demo.


    Edited to compensate with the problem that an empty url() in the background (or background-image) property is filled with the URL of the current page. This makes for quite a bulky if statement, but it does at least work reliably (so far as I can currently tell), which is an improvement on the above. Latest iteration:

    function hideBox() {
        var href = document.location;
        var $eP = $('.elemproduct');
        $eP.each(
    
            function() {
            var imgString = $(this).css('background-image');
            var srcString = imgString.replace('url(','').replace(')','');
                if (!imgString || imgString == 'none' || srcString == href) {
                    $(this).hide();
                }
            });
    }
    hideBox();
    

    JS Fiddle demo.


    Edited and amended the above, to remove the unnecessary variable (srcString) and its multiple calls to .replcace():

    function hideBox() {
        var href = document.location;
        var $eP = $('.elemproduct');
        $eP.each(
    
            function() {
            var imgString = $(this).css('background-image');
                if (!imgString || imgString == 'none' || imgString.indexOf(href) > -1) {
                    $(this).hide();
                }
            });
    }
    hideBox();
    

    JS Fiddle demo.


    Edited in response to comment from OP:

    I’m trying to get it working but under chrome everything is shown, IE everything is hidden. Even if I see that your code works under jsfiddle … I’m not understanding everything, i.e imgString.indexOf(href) > -1.

    The if tests for three conditions:

    1. !imgString, if there’s no string returned from the background-image property of the .css() method.
    2. imgString == 'none', because jQuery (sometimes, or possibly always) returns ‘none’ if there is no defined background-image.
    3. imgString.indexOf(href) > -1. This looks at the imgString variable to see if it contains the string contained by the variable href. If the string is found it returns the position at which it was found; if it was not found it returns -1.

      var string = "abcdef";
      alert(string.indexOf('a')); // alerts: 0
      

    JS Fiddle demo.

        alert(string.indexOf('bc')); // alerts: 1
    

    JS Fiddle demo.

        alert(string.indexOf('ef')); // alerts: 4
    

    JS Fiddle demo.

        alert(string.indexOf('x')); // alerts: -1
    

    JS Fiddle demo.

    This is to check that the empty url() in CSS isn’t simply being filled automatically by the browser.


    Edited after being pointed at the URL for the page and finding that the use of PHP and GET made things a tad more awkward than I’d imagined.

    Using the following in the console (certainly in Chromium) worked:

    $('.elemproduct').each(
        function() {
            if ($(this).css('background-image') == 'url(' + document.location.toString().substring(0, document.location.href.toString().indexOf('index')) + ')') {
                $(this).hide();
            }
        });
    

    The above, working in JS Fiddle and implemented into the hideBox() function:

    // in real life use:
    // var urlString = document.location.href;
    var urlString = 'http://www.infiniscale.com/beta/index.php?id=48';
    
    
    function hideBox() {
        var href = document.location;
        var $eP = $('.elemproduct');
        $eP.each(
            function(){
                if ($(this).css('background-image') == 'url(' + urlString.substring(0,urlString.indexOf('index')) + ')'){
                    $(this).hide();
                }
            });
    }
    hideBox();
    

    A demonstration of the above is available at JS Fiddle!

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

Sidebar

Related Questions

I am porting some queries from Access to T-SQL and those who wrote the
I wrote these lines: foreach (var catId in CatIds) { AdCategory.AdId = LastAd.AdID; AdCategory.CategoryId
I wrote these lines in My Application start event: var mongo = new Mongo();
I wrote a simple Tkinter based Python application that reads text from a serial
I have been trying PyMC these days, and I wrote a very simple mcmceasy.py.
I wrote a very simple C# application to send Tweets between to Windows machines.
Background: Those of you who use FF3 may be familiar with an interesting new
I wrote a simple drawing program, and for to create a menu, I used
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I need to write a SQL query which will get me those rows from

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.