0

Below is my script which is suppose to show the user a greeting message based on their local time. I got the script from another stack overflow answer, but am having trouble with replacing the image src. I get the following error

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8888/neil-wp/imgurl%20+%20second.jpg


$(document).ready(function () {
    datetoday = new Date(); // create new Date()
    timenow = datetoday.getTime(); // grabbing the time it is now
    datetoday.setTime(timenow); // setting the time now to datetoday variable
    hournow = datetoday.getHours();  //the hour it is
    imgselector = $('#greeting-img')
    imgpath = 'wp-content/themes/neil/img/'

    if (hournow >= 16.5) { // if it is after 4:30pm
        imgselector.attr("src","imgpath + goodevening.gif");
    }  
    else if (hournow >= 12) { // if it is after 12pm
        imgselector.attr("src","imgpath + goodafternoon.gif");
    } 
    else if (hournow >= 0) { // if it is after midnight
        imgselector.attr("src","imgpath + goodmorning.gif");
    }
});

// Wait for window load
$(window).load(function() {
    $(".greeting").delay(2000).fadeOut("200");
});

Here is my HTML

<div class="greeting">
    <div class="greeting-inner">
    <img id="greeting-img" src="">
    </div>
</div>

1 Answer 1

2

as imgpath is variable, use:

imgselector.attr("src",imgpath + "goodmorning.gif");
Sign up to request clarification or add additional context in comments.

Comments

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.