0

I'm not much of a coder to be fair so this is probably really simple.

I've moved this piece of code from inline to external but since doing so it has stopped working.

I'm wondering what it is that I need to change to make it work.

function lazy_load_html() {
    jQuery(document).ready(function($){
        if (navigator.platform == "iPad") return;
        jQuery("#content,#footer").find("img").lazyload({
            effect:"fadeIn",
            placeholder: "http://www.domain.com/long-path/grey.gif"
        });
    });
4
  • Is this the complete copy from the external file? If it is, you're missing the closing }. Commented Nov 9, 2010 at 22:17
  • where are you calling lazy_load_html()? Commented Nov 9, 2010 at 22:31
  • HEy James thanks for your response. Removing that fixed it. Thanks. Commented Nov 9, 2010 at 22:50
  • That was thanks to stackoverflow.com/users/157247/t-j-crowder Commented Nov 9, 2010 at 22:50

2 Answers 2

1

From your comment to James:

It seems like there's something missing from it. I thought a "}" but not matter where I add one of them it doesn't work :-(

The missing } should be at the end:

    function lazy_load_html() {
        jQuery(document).ready(function($){
            if (navigator.platform == "iPad") return;
            jQuery("#content,#footer").find("img").lazyload({
                effect:"fadeIn",
                placeholder: "http://www.domain.com/long-path/grey.gif"
            });
        });
    }
//  ^-- here

Other things to check:

1) You'll want to be sure that the script tag for this external file is after the jquery.js one.

2) Make sure something somewhere is actually calling the lazy_load_html function, or get rid of it. If getting rid of it, just remove the first and last line of the above, like so:

jQuery(document).ready(function($){
    if (navigator.platform == "iPad") return;
    jQuery("#content,#footer").find("img").lazyload({
        effect:"fadeIn",
        placeholder: "http://www.domain.com/long-path/grey.gif"
    });
});

There's no particular reason you need to have it in its own function, the jQuery(document).ready part already handles deferring actually doing the hooking up of the images for you.

Sign up to request clarification or add additional context in comments.

3 Comments

I added that in and it still doesn't work.. It has me really confused because they are in the right order too Jquery then the file that has this in it.
This worked like a charm. I think also chaning the order in the no jquery.js file helped too. Not sure if it did but everything you referenced made it work. Now working sweet as. Thanks very much dude. Highly appreciated and have a great day dude and a happy future. :D Maybe we'll meet one day again in the mounds of questions on StackOverflow hehe. Great work. So happy now I can go to bed knowing it's working and saving my bandwidth.
@Mark: Glad that helped. If this answered your question, please click the empty checkmark to the left of the beginning of this answer. That marks your question as "answered". (More here: stackoverflow.com/faq)
0

There should be no difference in the execution of code inline or in an external file.

Have you changed the place where you include the external file - it should be in the same place as the inline code to be sure it will do exactly the same thing.

Are you sure you are correctly including the external file - if not can you post how you are doing that?

1 Comment

All other javascript in the external file works fine apart from this code.. :-( It seems like there's something missing from it. I thought a "}" but not matter where I add one of them it doesn't work :-(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.