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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:23:51+00:00 2026-05-24T17:23:51+00:00

This is a javascript meant to be a part of chrome extension. It should

  • 0

This is a javascript meant to be a part of chrome extension. It should print out id when I press the add button.
What it does, though, is I have to press add TWICE to have the id appended where I want it to ( I use this instead of alert)
When debugging, it says that bookmarkBarID is undefined… I suppose this is the error but I dont know how to fix it. Please help
here is the whole code:

<!doctype html>
<html>
    <head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script>
var bookmarkBarID;
function getBM(){
chrome.bookmarks.getTree(function(tree){ 
bookmarkBarID=tree[0].children[0];
}); 
}



function CreateNewItem()
{
$('#submit').click(function (){
getBM()
console.log(bookmarkBarID);
$('.bookmark').append(bookmarkBarID.id);
})
}

    </script>
    </head>
<body onload="CreateNewItem();" style="width:1200px">
<div class="bookmark"></div>
  <input type="text" value="enter url here" id = 'urlLink' />
  <input type="text" value="enter Name title" id='linkName'/>
  <input type="text" value="" id='folderName' />
  <div><button id="submit">Add</button></div>
</body>
</html>
  • 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-24T17:23:52+00:00Added an answer on May 24, 2026 at 5:23 pm

    chrome.bookmarks.getTree is an asynchronous function, which means that it runs at the same time as your other code. The function finishes after the rest of your code executes. To use the function’s results, you need to give a callback function that will be called with the results. In this case, you need to move $('.bookmark').append(bookmarkBarID.id); into the callback function:

    function getBM(){
    chrome.bookmarks.getTree(function(tree){ 
    bookmarkBarID=tree[0].children[0];
    console.log(bookmarkBarID);
    $('.bookmark').append(bookmarkBarID.id);
    }); 
    }
    
    
    
    function CreateNewItem()
    {
    $('#submit').click(function (){
    getBM();
    })
    }
    

    Note: you should use $(document).ready(CreateNewItem); instead of onload (assuming that you are using jQuery).

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

Sidebar

Related Questions

i have this javascript code to which i want to add the jquery fade-in
This is part of a code. The question is, does this line $(#b_facetNewChild).button().click(function(){ means
BEFORE CHAOS I used to have this one... at the head part <script type=text/javascript>$(function()
This javascript code does not work in IE8, but works in Firefox and Google
Why does this javascript return 108 instead of 2008? it gets the day and
I have this Javascript data: [{id:123,type:test},{id:154,type:another}] How would you transform that into something so
I have this javascript code below that uses jquery, it is suppoed to be
1) I have this Javascript array: lang=new Array(); lang[sq]=Albanian; lang[ar]=Arabic; lang[en]=English; lang[ro]=Romanian; lang[ru]=Russian; 2)
I have this JavaScript code: for (var idx in data) { var row =
I have a user control that is cached and as part of this control,

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.