Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Build an XML-based Tree Control with JavaScript : Page 3

Tree controls provide a hierarchical view of data and XML provides a way to structure data hierarchically, so viewing XML data as a tree structure is a natural fit. But browsers don't provide a tree control. Instead, use this mix of XML, XSLT, JavaScript, and CSS to produce an extensible HTML tree control.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Create JavaScript and CSS Files
You'll need to create the JavaScript and CSS files next. The JavaScript file contains the variables and functions to make the tree work in a browser and the CSS stylesheet controls how the browser formats the text in the tree control.

Here's the content of the JavaScript file:

var openImg = new Image(); openImg.src = "open.gif"; var closedImg = new Image(); closedImg.src = "closed.gif"; function showBranch(branch){ var objBranch = document.getElementById(branch).style; if(objBranch.display=="block") objBranch.display="none"; else objBranch.display="block"; swapFolder('I' + branch); } function swapFolder(img){ objImg = document.getElementById(img); if(objImg.src.indexOf('closed.gif')>-1) objImg.src = openImg.src; else objImg.src = closedImg.src; }

Save the completed JavaScript file as xmlTree.js.

Here's the code for the CSS file:

body{ font: 10pt Verdana,sans-serif; color: navy; } .trigger{ cursor: pointer; cursor: hand; display: block; } .branch{ display: none; margin-left: 16px; } a{ text-decoration: none; } a:hover{ text-decoration: underline; }

Save the completed CSS file as xmlTree.css.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date