0

I have tried to create my first One Note Add In using the JavaScript API. I have tried the example in the MS documentaion (Build your first OneNote task pane add-in). This one works.

Now I want to try to change the formatting of an element in the document. For example I want to change the font colour of a text. However, I have not yet found a way to access the elements in a document.

Can I access elements in a document via a JS Add In to change their "style" property? How can I do that?

Thanks Micheal

  • https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById – Jeremy Anderson Nov 24 '20 at 21:03
  • Hi @JeremyAnderson , thanks for your input. I tried to give the list item an id and access it by "document.getElementById()", It does not work. Then I tried to search for the element with "document.querySelectorAll()" and recognized, that I can only access the html-page provided with the script, but not the content of the OneNote document. Does anybody knows how to get access to the OneNote document itself? – Michael Neumair Nov 25 '20 at 17:15

1 Answers1

0

Finally, I found a way to access the OneNote page content from the JS Add In. You can load the page content using

var page = context.application.getActivePage();
var pageContents = page.contents;

context.load(pageContents);

Now you have access to the page content in the qued commands.

return context.sync().then( function() {

  var outline = pageContents.items[0].outline;    
  outline.appendHtml("<p>new paragraph</p>");

  var p = outline.paragraphs;
  context.load(p);
  ...
});

So consequently you can access element by element in document the hirarchy.