Binding of a dom element to a javascript variable

I'm new to js and my task is this: I've to bind a gauge object like one you can download from this rep: https://github.com/Mikhus/canv-gauge.git

to a dom element in order to get it from c++ software. How can I create my var and set it with id, just to use GetElementFromId dom method?

thank you, Daniele

Answers:

Answer

You can try it with jQuery.

Here is the example:

var elt = document.getElementById('dom-id');
jQuery.data(elt, "gauge", gaugeObject);

Be careful that the first argument of jQuery.data() is a DOM object, instead of a jQuery object.

When you want to get the binded object, use

var gaugeObject = jQuery.data(elt, "gauge");
Answer

If you want to interact between JavaScript code and a host C++ app (like an app built with V8, CEF or Minko), you can:

  • call eval from the C++ host (for example Minko provides the AbstractDOM::eval() method) using the code provided by cipher
  • call methods specific to the C++ host implementation, for example Minko provides a two-way C++/JS messaging system described here

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.