The problem is this, I tried to invent a bicycle, well, so to speak, to repeat Java Script, invented it, it worked, then it stopped, I can’t understand what the problem is (I didn’t bother with cross-browserism, so don’t blame it, to make it work). Here is the code.

That's what I wanted to invent (jQuery); this code works ...

$('img').each(function() { if($(this).width()>500) $(this).fadeOut(4000); }) 

And here is the Java Script

 var obj = document.getElementsByTagName('img'), k = 0, arr = new Array(), i, n; for (i = 0; i < obj.length; i++) if (obj[i].width > 500) { arr[k] = obj[i]; k++; } n = k; k = 1; function opacity_() { if (k <= 0) { clearInterval(id); for (i = 0; i < n; i++) arr[i].style.display = 'none'; } else { for (i = 0; i < n; i++) arr[i].style.opacity = k; k -= 0.004; } } opacity_(); var id = setInterval(function () { opacity_(); }, 10); 

says that obj.length = 0 , the question is easy in principle, but I’m dumbing for something; )) There are images in the document that have a width=960px .

    2 answers 2

    Are you sure the code runs after the DOM has been built? Since there are large pictures on the page, it is likely that they do not have time to load.

    • Tochnyak, HOUSE tree is not built, thanks =) - Eugene536
    • And how to make an analog jQuery $(function() { } in javascript? - Eugene536
    • one
      window.onload = function () {} or setTimeout (function () {}, 0), although I doubt the second option. - ling
    • Thanks, but I was looking in document.onload ...) - Eugene536

    Apparently, the script is before the images.

    • Yes, yes, before the images. - Eugene536 1:58 pm