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

  • Home
  • SEARCH
  • 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 6534455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:15:10+00:00 2026-05-25T10:15:10+00:00

i have the following basic script to make an api call to vimeo and

  • 0

i have the following basic script to make an api call to vimeo and insert the embed to a div #embed. I’m having trouble however getting it to grab the text of another div #embedthis and assembling the api call from that.

The code below does work if placed in the <body>. However I want to set this up properly as I would like to also be able to change the content of #embedthis dynamically, updating the displayed embed. Any help is so much appreciated!

script:

  // URL to get embed
  var videoUrl = document.getElementById('embedthis').innerHTML; 

  // oEmbed endpoint for Vimeo using JSON

  var endpoint = 'http://www.vimeo.com/api/oembed.json';

  // Tell Vimeo what function to call
  var callback = 'embedVideo';

  // Put together the URL
  var url = endpoint + '?url=' + encodeURIComponent(videoUrl) + '&callback=' + callback + '&width=640';

  // put video on page
  function embedVideo(video) {
      document.getElementById('embed').innerHTML = unescape(video.html);
  }

  // load data from Vimeo
  function MakeEmbed() {
      var js = document.createElement('script');
      js.setAttribute('type', 'text/javascript');
      js.setAttribute('src', url);
      document.getElementsByTagName('head').item(0).appendChild(js);
  };

  window.onload = MakeEmbed;

view:

<div id="embed">
  ...
</div>

<div id="embedthis">http://vimeo.com/24453255</div>

With this I get document.getElementById('embedthis')" is null, probably because #embedthis isn’t loaded yet.

  • 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-05-25T10:15:11+00:00Added an answer on May 25, 2026 at 10:15 am

    The issue is that when var videoUrl = document.getElementById('embedthis').text() is called, the <div> has yet to be created by the browser, since this code is called as soon as the browser encounters it, which I assume is in your <head> section.

    Your code should work if you move it to a function which is called on window.onload or document.ready as this guarantees that the element has been created.

    Edit

    Like so (comments removed for brevity):

    var url;
    function embedVideo(video) { ... }
    
    var my_onload = function() {
        var videoUrl = document.getElementById('embedthis').innerHTML; 
        var endpoint = 'http://www.vimeo.com/api/oembed.json';
        var callback = 'embedVideo';
        url = endpoint + '?url=' + encodeURIComponent(videoUrl) + '&callback=' + callback + '&width=640';
        MakeEmbed();
    }
    
    window.onload = my_onload;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following basic function: <script type=text/javascript> function Form_Data(theForm) { var t=1; while
I have the following fairly basic greasemonkey script: var newloc = location.href.replace(/^(.*)-xyz-(.*)$/i, $1$2); if
currently i have jdbc code with the following basic stucture: get Connection (do the
I have the following code $curl_handle = curl_init(); $api_url = 'http://api.twitter.com/1/statuses/home_timeline.json'; curl_setopt($curl_handle, CURLOPT_URL, $api_url);
I have the following code, which is the basis for pagination in a larger
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following situation. A main table and many other tables linked together with
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party

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.