Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
Greg311
Posts: 9
Registered: ‎04-23-2013
My Device: Don't have BB :(
My Carrier: Orange PL
Accepted Solution

JavaScript can't find existing div

Hi! I try write some test app in HTML5 and i have one problem. Here is code:

<div data-bb-type="screen" data-bb-efect="fade" data-bb-indicator="true" data-bb-scroll-effect="off">
	<script type="text/javascript">
		function touchpanel() {
			var item = new Array();
			var objTo = document.getElementById("touchtest");
			
			alert(objTo);
			for(var i = 0; i < 240; i++)
			{
				item[i] = document.createElement('div');
				item[i].className = "sprite";
				item[i].id = i;
				item[i].ontouchmove=function(e) {
					event.target.className = "green";
				}
				item[i].ontouchstart=function(e) {
					event.target.className = "green";
				}
				
				objTo.appendChild(item[i]);
			}
		}
		
		window.addEventListener("load", touchpanel());
	</script>
	<div id="touchtest"></div>
	
	TOUCHPANEL
	<div data-bb-type="action-bar">
      <div data-bb-type="action" data-bb-style="button" data-bb-overflow="true" data-bb-img="cog.png" onclick="bb.pushScreen('lcd.html','lcd');">LCD</div>
	  <div data-bb-type="action" data-bb-style="button" data-bb-overflow="true" data-bb-img="cog.png" onclick="bb.pushScreen('touchpanel.html','touchpanel');">Touch Panel</div>
	  <div data-bb-type="action" data-bb-style="button" data-bb-overflow="true" data-bb-img="cog.png" onclick="bb.pushScreen('multitouch.html','multitouch');">Multitouch</div>
	  <div data-bb-type="action" data-bb-style="button" data-bb-overflow="true" data-bb-img="cog.png" onclick="bb.pushScreen('sensors.html','sensors');">Sensors</div>
	  <div data-bb-type="action" data-bb-style="button" data-bb-overflow="true" data-bb-img="cog.png" onclick="bb.pushScreen('phone.html','phone');">About Phone</div>
	  <div data-bb-type="action" data-bb-style="button" data-bb-overflow="true" data-bb-img="cog.png" onclick="bb.pushScreen('author.html','author');">Author</div>
  </div>
</div>

This file is pushed from index.html. Unfortunately js can't find #touchtest div. But if i use only first.html file all works. Can you help me? You can test it: http://www.grzesieq94.uh.net.pl/bbtest

Please use plain text.
BlackBerry Development Advisor
rcraigbarnes
Posts: 40
Registered: ‎01-11-2013
My Device: BlackBerry Z10
My Carrier: Rogers

Re: JavaScript can't find existing div

[ Edited ]

It looks like you are using bbUI.js. if you are you should be using onscreenready (or ondomready depending on what you are doing) to trigger your screen related JS. Details can be found at https://github.com/blackberry/bbUI.js/wiki/Toolkit-Initialization but basically they fire after all your screen related stuff is processed.

--
Website Relations - Web Technologies

@roryboy

1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the like/thumbs up button below the post(s)
Please use plain text.
New Developer
Greg311
Posts: 9
Registered: ‎04-23-2013
My Device: Don't have BB :(
My Carrier: Orange PL

Re: JavaScript can't find existing div

Thank you! It works!
Please use plain text.
Regular Contributor
kotji
Posts: 94
Registered: ‎07-30-2012
My Device: Os7.1
My Carrier: Dtac Thailand

Re: JavaScript can't find existing div

<div data-bb-type="screen" data-bb-efect="fade" data-bb-indicator="true" data-bb-scroll-effect="off"> &lt;script type="text/javascript"> function
Please use plain text.