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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:20:24+00:00 2026-06-06T07:20:24+00:00

I have a javascript link that references another .js file. I’ve been trying to

  • 0

I have a javascript link that references another .js file. I’ve been trying to output an image (for testing purposes), but I’m not sure what is the correct way to go about this.

    alert("beginning");
    //var link = $("<a href='http://juixe.com'>Hello, <b>World</b>!</a>");
    //$('body').append(link);
    //document.write("hi");
    //document.write("<div><img src='http://s3-media2.ak.yelpcdn.com/bphoto/xqC6Iy5mOLb_8mwMKGv8_w/l.jpg' /></div>");
    alert("before function");
(function(){



    alert("middle");
    var links = $("<a href='http://juixe.com'>Hello, <b>World</b>!</a>");
    $('body').append(links);
    alert("after middle");
    //alert($("img").attr("id"));
    document.write("hi");
    document.write("<div><img src='http://s3-media2.ak.yelpcdn.com/bphoto/xqC6Iy5mOLb_8mwMKGv8_w/l.jpg' /></div>");

    alert("end");
}());

I was able to alert beginning, all the way to middle. It seems like var links doesn’t work. I’m trying to use HTML inside this .js file. Essentially, I want to be able to do some modal window, but I’m trying to output images for testing purposes right now.

Also, is this the correct way for jquery?

Thanks in advance!

  • 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-06T07:20:26+00:00Added an answer on June 6, 2026 at 7:20 am

    Your code is a strange mix. Jquery code almost always needs to run after the page has loaded whereas document.write can never be used after the page has loaded.

    You are incorrectly wrapping your jQuery in an immediate executing function. The proper wrap for jQuery is within :

    $(document).ready(function(){
      /* html of page exists now, run jQuery here */
    });// notice no extra "()" after close brace as you have
    

    or the shorthand version that does same thing:

    $(function(){
      /*html of page exists now, run jQuery here */
    });// notice no extra "()" after close brace  as you have
    

    If you change all of your document.write to $('body').append(/* your content*/) and place all your code inside the above wrappers you will have much better success.

    There is a wealth of information within the jQuery documentation and API. A good start point with more detail about the wrapping I’ve shown can be found here: http://docs.jquery.com/How_jQuery_Works

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

Sidebar

Related Questions

I have a link, that when I click it calls a javascript function with
I have Javascript that opens another window and registers a click handler for all
I have an aspx page that includes a javascript file in the head tag.
This seems really simple but Im brand new to JavaScript. I have a link
I have a timer in my JavaScript which needs to emulate clicking a link
I have the following js files in my code for EditInPlace... <?php echo $javascript->link('jquery.js');?>
I have JavaScript that is doing activity periodically. When the user is not looking
I have javascript code embedded inside a html template file. When I load this
I have JavaScript code which copies the value of input file and paste it
I have javascript string variable with var sttr=We prefer questions that can be answered

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.