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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Developer
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");
			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";
		window.addEventListener("load", touchpanel());
	<div id="touchtest"></div>
	<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>

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

BlackBerry Development Advisor
Posts: 43
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.

Senior Systems Software Developer - Enterprise R&D


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)
New Developer
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!
Regular Contributor
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