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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:50:41+00:00 2026-06-16T09:50:41+00:00

function CheckavailOnload() { var elems = document.getElementsByClassName(‘box-collateral box-related’); var av = document.getElementsByClassName(‘availability in-stock’); var

  • 0
function CheckavailOnload()
{
  var elems = document.getElementsByClassName('box-collateral box-related');
  var av = document.getElementsByClassName('availability in-stock');
  var x;
  for (var i = 0; i < elems.length; i++)
  {
    if (getComputedStyle(elems[i]).visibility == 'visible') 
    {
      for (var j = 0; j < av.length; j++)
      {
        av[j].style.visibility = 'visible';
        if(elems[i].offsetTop < 0)
        {
          var x = (elems[i].offsetHeight + (elems[i]).offsetTop).toString() + "px";
          alert(x);
        }
        for(m = 0;m < av.length; m++)
        {
          av[m].style.Bottom = (-x);
          return;
        }
       }
     }
   }
   for (var k = 0; k < av.length; k++)
   {
     av[k].style.visibility = 'hidden';
   }
   var divs = document.getElementsByClassName('add-to-cart');
   for(var l = 0; l < divs.length; l++)
   { 
     divs[l].style.marginTop = (-500).toString() + "px";
     divs[l].style.marginLeft = (-20).toString() + "px";
   }
}
window.onload = CheckavailOnload;

here i am trying to move a paragraph tag have baground image depending upon the div offsetTop and Offset height div also have bacground image i am moving para tag just below the div but addition of offsetHeight and offsetTop is coming NAN please anyone can help me

  • 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-06-16T09:50:42+00:00Added an answer on June 16, 2026 at 9:50 am

    You’ve declared var x; at the beginning of your script. Then later you’re checking:

    if(elems[i].offsetTop < 0) {
        var x = (elems[i]...); // var is not recommended to be here, x has been already declared once
    }
    

    If elems[i].offsetTop happens to be >= 0, x will be undefined in this line:

    av[m].style.Bottom = (-x); // Notice a typo here: should be av[m].style.bottom
    

    This last expression gives you NaN. To avoid this, you need to either assign a default value to x in the beginning of the script, or add an else statement after the if wherein some numeric value is assigned to x.

    Also return in the for...m-loop seems to break your code, the loop will never finish the job and the rest of the code will be never executed.

    Using (-500).toString() + "px"; feels complex, why not just use "-500px";?

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

Sidebar

Related Questions

function CheckavailOnload() { var elems = document.getElementsByClassName('box-collateral box-related'); for(var i = 0; i <
function validateRequiredFields(formid) { var inputs = document.getElementsByClassName('required'); for(i=0;i<inputs.length;i++) { var FieldID = inputs[i].id; if(
function getWindowsUserName() { var WinNetwork = new ActiveXObject(WScript.Network); var urlToSite = createCustomURL(WinNetwork.UserName); document.getElementById(psyncLink).src =
function getUsername() { var userName = document.form.screen_name.value; document.getElementById(display).innerHTML = userName; var apiName = https://api.twitter.com/1/users/lookup.json?screen_name=
function trim(str,options){ var string = str.replace(/^\s\s*/, ''), ws = /\s/, i = str.length, j
function saveData() { var rows = $('#deviceTable tr').length; var toSave = ; alert(rows); for(var
function moreFields() { counter++; var newFields = document.getElementById(input).cloneNode(true); newFields.id = counter; newFields.style.display = 'block';
function levenshtein(a, b) { var i,j,cost,d=[]; if (a.length == 0) {return b.length;} if (b.length
function ExChgClsName(Obj,NameA,NameB){ var Obj=document.getElementById(Obj)?document.getElementById(Obj):Obj; Obj.className=Obj.className==NameA?NameB:NameA; } <a href=javascript:showMenu(2);> i am a newbie of the
function loadjscssfile(filename, filetype) { if (filetype==css) { var fileref = document.createElement(link); fileref.rel = stylesheet;

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.