0

I am working in Jquery Mobile and have hit my next brick wall, which I am hoping somebody will kindly point out where I am going wrong.

I have a collapsible widget which within I wish to amend the content with different values.

An example of my HTML

<div data-role="collapsible" data-mini="true" id="solar_collapsible">
<h3>Solar Power Information</h3>
<p id="solar_current"></p>
</div>

I am trying to amend id "solar_current" below:

document.getElementById("#solar_current").innerHTML = "Solar Current = 13";

Currently I receive this error in Google Chrome :-

Unable to set property 'innerHTML' of undefined or null reference

I have stripped my code back but after searching all afternoon I can not find any reference or other questions relating directly to this problem.

Has Solar_current not been created yet ? is this the reason for the error ?

Thank you very much.

Andy Donegan
  • 782
  • 1
  • 9
  • 30
  • Have you tried removing the "#" from getElementById? That's pretty exclusive to selector querying in jQuery – Steve Hynding May 06 '15 at 18:17
  • Thank you Steve, I spent last night on this as well, I had thought incorrectly because the element was within a collapsible widget it somehow was making it more complex. Yes you fixed it for me. Much appreciated. – Andy Donegan May 06 '15 at 21:11

1 Answers1

0

Seeing as you are using jQuery anyway, why not use it:

$("#solar_current").html("Solar Current = 13");

You can run this in the pagecreate event of the page.

If you want to use plain javascript, just remove the "#" as Steve Hynding suggested.:

document.getElementById("solar_current").innerHTML = "Solar Current = 13";
ezanker
  • 24,628
  • 1
  • 20
  • 35
  • Ezanker, Thank you for expanding upon it and showing me a better way to do it. I had written my own basic function to do this in another script but was using variables, when writing this one as I was just practicing I had copied and pasted the normal # into my code. I like the Jquery way you have put forward and will take that forward in to my code. Much appreciated. Andy. – Andy Donegan May 06 '15 at 21:13