Tree structure using Jquery / Javascript / Html

Hi Experts,

My web application was developed using C#/ASP.NET and for each menu/tab we have a help icon and if we click on help icon it should open a new browser window and should redirect to corresponding contents page (Html files) highlighting left hand side node (contents) and displaying details in the right hand side, similar to this tree structure (http://www.telerik.com/help/aspnet-ajax/introduction-common_changes_backward_compatibility.html).

Foar eg: from application we pass Page name( Page1,Subpage1...etc) like this http://testserver/mauals/index.html?Page1.htm (Assuming user has clicked Help icon on  Page1) and it should Highlight Page1 on the left side of Tree structure and display contents in the right pane.

Can any one help me (with sample code) for the above task  using Jquery/Javascript/Html ?

Thanks in advance
ksd123Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Scott Fell, EE MVEConnect With a Mentor Developer & EE ModeratorCommented:
You can do this on all serverside code (.NET), all client side (jquery/js) or a combo. I do this very thing on some of my internal db sites but I am using classic asp.    If using all serverside, you first need to grab the page name.  You can do this by hardcoding a variable called pageName for instance or what I do is grab the page name from the url.  I don't know how to do that in .net but this may help http://forums.asp.net/t/318949.aspx

Next on your tree code, you have to give the selected page some type of css class that will make it highlight.  

There are also plenty of jquery tree projects.  One is http://www.jstree.com/demo.  If you hard code a javascript variable called pageName, you can then use jquery to mark the appropriate li link with the class jstree-clicked and that will make the branch highlighted.

Using the jstree demo html
  <div id="demo1" class="demo" style="height:100px;">
	<ul>
		<li id="phtml_1">
			<a href="#">Root node 1</a>
			<ul>
				<li id="phtml_2">
					<a href="#">Child node 1</a>
				</li>
				<li id="phtml_3">
					<a href="#">Child node 2</a>
				</li>
			</ul>
		</li>
		<li id="phtml_4">
			<a href="#">Root node 2</a>
		</li>
	</ul>
</div>

Open in new window

You can targe an anchor branch (the 'a' uder the 'li') with jquery like this
  <div id="demo1" class="demo" style="height:100px;">
	<ul>
		<li id="phtml_1">
			<a href="#">Root node 1</a>
			<ul>
				<li id="phtml_2">
					<a href="#">Child node 1</a>
				</li>
				<li id="phtml_3">
					<a href="#">Child node 2</a>
				</li>
			</ul>
		</li>
		<li id="phtml_4">
			<a href="#">Root node 2</a>
		</li>
	</ul>
</div>

Open in new window

I have a working sample I made where I added css to make the targeted a link large.  You can see I hardcoded the page name to match the id of the li.http://jsbin.com/iSEcUBU/1/edit?html,css,js,output
$( document ).ready(function() {
  var pageName="phtml_2";
  $('div#demo1 ul li').each(function(){
    if($(this).attr('id')==pageName){
       $(this).find('a').addClass('jstree-clicked ');
    }
    
  });
});

Open in new window

If you need a little refresher or start with jquery spend a few hours on http://www.codecademy.com/learn
0
 
Michel PlungjanIT ExpertCommented:
There was nothing on Google that fit your needs?

First thing I came across was http://jquery-plugins.net/tag/treeview
0
 
ksd123Author Commented:
Thanks padas for your sample code and appreciate your time.

1) I need one more help,in the tree structure left pane shows (Root node 1,child node 1 etc)  and  need  sample code that  shows Details of the Highlighted node  in the Right pane  using Jquery / HTML?

2)I  just want to double check with you that the below JQuery code for highlighting selection of node will be compatable with all browsers (ie7,ie8,ie9,google chrome etc) ?, I heard that  sometime's it may not work (Highlight) in some browsers. Can you suggest me on this ?

$(this).find('a').addClass('jstree-clicked ');
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I develop on a mac and personally don't support the older browsers in anything I do.  I understand the need for corporate account though.  

The first step is using the jstree demo in ie7,8 and 9.  If that works, then it should be good.   The code $(this).find('a').addClass('jstree-clicked '); is simply adding a class to the anchor so you end up with <a class="stree-clicked" href="#">something</a>.   Jquery 1.x supports the older ie browsers.  Jquery 2.x is lighter weight because they took out the support for older browsers.  So as long as you are using jquery 1.x all should be good.  

I would still suggest making a quick sample page and testing it first.
0
 
ksd123Author Commented:
I have created sample page and it's working fine  in all browsers and just need  sample code that  shows Details (static content) of the Highlighted node  in the Right pane  using Jquery / HTML?
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
>just need  sample code

http:Q_28277863.html#a39602888

If you take the time to recreate the sample code including html, project css and js, you will see this works.
0
 
ksd123Author Commented:
Thank you Padas.

I am just asking sample code for the right pane, in the tree structure if I click on "Child node 1" it should display some static content related to "Child node 1"in the right pane  similar to this (http://www.telerik.com/help/aspnet-ajax/introduction-common_changes_backward_compatibility.html).
0
 
ksd123Author Commented:
Thank you so much
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.