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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:35:01+00:00 2026-06-07T12:35:01+00:00

All my js scripts are working, but this is not working $(img).each(function() { if

  • 0

All my js scripts are working, but this is not working

 $("img").each(function() {
      if ($(this).height() > 100) {
        return $(this).after("<p class='tasr'>FOTO © TASR</p>");
      }
    });

When I load page, it’s not work, but when I copy this script do chrome-console, it work perfect.

My coffee script:

jQuery $(document).ready -> 
    $("img").each ->
        if $(this).height() > 100
            $(this).after("<p class='tasr'>FOTO © TASR</p>")

EDITED:

This is my dirty code: My javascript code from coffeescript

  • 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-07T12:35:04+00:00Added an answer on June 7, 2026 at 12:35 pm

    This might be down to the fact that the images havent finished loading yet and so return a height and width of 0.

    You probably want to use .load() function on the image which will be triggered once the image loads and therefore will have a width and height greater than 0.

    This would also explain why it is working in the chrome console since by then the images will have loaded.

    EDIT: Something worth noting mentioned by @zzzzBov in a comment below is that the cache in browsers will often stop the image calling the load function on a standard refresh. To get around this you just need to have a function with all your code in which you call from both the .load function and inside the document ready function

    If this is your html:

    <img id="img1" src="example.jpg" />
    

    Then you can write something along the lines of this in your script. Note this is off the top of my head so it might be slightly wrong.

    function doStuff() {
        //I normally do a check here to see if the image width/height is 0 if it is then I dont bother
        //executing the rest
    
        //I do however sometimes need to do stuff when the image has not yet loaded which can be done here.
    
        //do stuff with the image, you could also pass parameters if needed.
    }
    
    $(document).ready(function() {
        doStuff();
    });
    
    $('#img1').load(function() {
        doStuff();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know people complain usually about scripts not working, but here is a case
I have this login script, but for some reason its not working. I checked
The dillema is like this: If I try to fit all the scripts blocks
I don't know whether all coffeescript compilers wrap their scripts in anonymous functions, but
I can't seem to work out why this simple .parent() is not working. Currently
I've been working on this extensively for the past week and I can not
I'm working on a 2d Game. I use lua script in all game logic.
Is there a font that supports all scripts? Ideally and Apple font, so I
My goal is to override the reference to the topmost window for all scripts
I have created total 50 test scripts. All these scripts use almost same objects

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.