1

I am curretnly working with some html, css and JS stuff and I am run into a problem. I have absolutly no idea why but I can' t access element in javascript using getElementById or jquery tag.. anything...

Here is html code of my element:

<div id="activeTickets" class="cardmenu_ActiveTickets">
    <div id="txt_ActiveTickets" class="Title FontLightGreen">Active tickets:</div>
</div>

here is JS code :

alert($("#txt_ActiveTickets"));
alert(document.getElementById("txt_ActiveTickets"));
if(document.getElementById("txt_ActiveTickets")!= undefined){
    document.getElementById('txt_ActiveTickets').innerHTML = Model.GetTranslateText();

}

this is happeing in JS function with name onTranslate() which is called here :

$( document ).ready(function() {
      InitVariables();
      ShowForm();
      onTranslate();
});

In the function there are ten other divs set with the same code, only with different id, and all other divs works except for this one.. I absolutly have no idea what' s wrong.

I am sorry I can't really tell how exactly the html works with c++. It's project in my work. My colleague is making a c++ part of program and I am making the html,css,javascript stuff. As far as I know it's only connected by html5viewer object and each html page has it's model which is set for the every page and in the JS script then to access c++ function you just use Model.function(). That's should be the only connection to html. It only create html5viewer which displays the pages in html.

eraz
  • 57
  • 9
  • 4
    Not sure what you expect to see in an `alert()` of a DOM node. Why don't you use the browser developer tools? Set a breakpoint or, at least, use `console.log()`. – Álvaro González May 15 '17 at 11:31
  • 1
    What error do you get? Do you see an alert? – titech May 15 '17 at 11:32
  • I am just trying to see if I am accessing the element or not... But I am getting null.. I already check console and there is no error... and I can't set a breakpoint because it's aplication built on c++ but using html graphics interface... so in javascript I am using c++ functions and when I am trying to debug it in browser it fail because I have no access to c++ function there – eraz May 15 '17 at 11:34
  • to test what ids are available for selection - can test by doing `$.each('div', function(i, v) {console.log($(this).attr('id');});` – treyBake May 15 '17 at 11:35
  • @tipura with javascript getElementById I get alert null and with jquery I get some [Object object] but I can' t do anything with it – eraz May 15 '17 at 11:35
  • well problem is that when i open the html file itself in browser it works.. I only can't access my element in my c++ aplication when I run it – eraz May 15 '17 at 11:37
  • Ok. but then it's not a pure HTML/JavaScript related problem. Please edit your question and explain how this works with c++ – titech May 15 '17 at 11:43
  • @eraz try `alert($("div[id=txt_ActiveTickets]"))` .... or ..... change div attribute id with `name` and try `alert($("div[name=txt_ActiveTickets]"))` . Hope that helps you. – ARr0w May 15 '17 at 11:45
  • When you open it in your C++ Application.... how is it in your C++ Application? – epascarello May 15 '17 at 11:52
  • http://stackoverflow.com/questions/8739605/getelementbyid-returns-null – epascarello May 15 '17 at 11:53
  • I added some basic information about c++ aplication thath I know – eraz May 15 '17 at 11:55

1 Answers1

0

Isn't div id must be div id="activeTickets" ? Because by using div id="txt_ActiveTickets", you got the div id for question, not the answer. Also you can use another div id for answer. Try this.

SanduniC
  • 41
  • 5