Home arrow JavaScript arrow Page 3 - Using Multiple Containers to Build Pop Up DIVs with the DOM and AJAX
JAVASCRIPT

Using Multiple Containers to Build Pop Up DIVs with the DOM and AJAX


If you're a web developer who wants to expand your background in building AJAX-based applications, I’m pretty certain that this article will be helpful to you. Welcome to the second part of the series “Building pop-up DIVs with the DOM and AJAX.” This series goes through creating pop-up boxes, which can be used in any web page to display additional information pulled from static or dynamic sources.

Author Info:
By: Alejandro Gervasio
Rating: 3 stars3 stars3 stars3 stars3 stars / 2
February 07, 2007
TABLE OF CONTENTS:
  1. · Using Multiple Containers to Build Pop Up DIVs with the DOM and AJAX
  2. · Going backwards: the original pop-up generating script
  3. · Working with multiple pop-up DIVs
  4. · Listing the improved version of the pop-up generating application

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using Multiple Containers to Build Pop Up DIVs with the DOM and AJAX - Working with multiple pop-up DIVs
(Page 3 of 4 )

As I stated in the beginning of this article, the primary goal here is to improve the original application in such a way that it can work with many pop-up DIVs in the same web page, and certainly not just one.

Therefore, I'll simply define a new JavaScript function that will check to see whether a specific web page element has the value "popupcontainer " for its class attribute. If this condition is true, the appropriate event handlers will be attached to the aforementioned element, in this way "activating" a new pop-up box for that container.

Does this sound a bit confusing? It shouldn't. Now, to clarify any eventual doubts, please examine the signature for this brand new function, which has been named "activatePopupDivs()". It looks like this:

// activate pop-up DIV elements
function activatePopupDivs(){
   var divs=document.getElementsByTagName('div');
   if(!divs){return};
   for(var i=0;i<divs.length;i++){
     if(divs[i].className=='popupcontainer'){
       // display pop-up DIV element
       divs[i].onmousemove=displayPopupDiv;
       // hide pop-up DIV element
       divs[i].onmouseout=hidePopupDiv;
     }
   }
}

As you can see, the definition for the above function is indeed short and straightforward. The referenced function simply loops over all the DIVs included in the corresponding web document and verifies whether these elements have a value of "popupcontainer" for their class attribute. In that case, the pair of "displayPopUpDiv()" and "hidePopUpDiv()"  functions that were shown in the first article are tied to the element in question, which implies that after running the previous function, multiple pop-up DIVs can be included into the same web page. Pretty good, right?

Also, you should notice that the "activatePopupDivs()" function traverses all the DIVs contained in the web document, which can sometimes be an unnecessary and time-consuming process. Nevertheless, this condition can be easily modified to loop over all the elements that belong only to a specific area within the respective web page.

Okay, now that you hopefully learned how to create a short JavaScript function that provides the overall application with the capacity for using multiple pop-up DIVs, it's time to leap forward and see how the complete script looks after incorporating the new function that I explained before. Besides, I'll introduce a small change to the original "displayPopUpDiv()" function to fix the browser compatibility issue related to Internet Explorer that I mentioned in the introduction of this tutorial.

To see how all of these improvements will be incorporated into the original pop-up generating application, click on the link below and read the following section.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials