Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-08-2013, 03:45 PM   PM User | #1
m2244
Regular Coder

 
Join Date: Jun 2012
Posts: 129
Thanks: 1
Thanked 1 Time in 1 Post
m2244 is an unknown quantity at this point
Should I do this with HTML or jQuery loop

Hello,

Right now I have some HTML code on my page that will be used for a glossary feature. I am wondering if I should create this list with jQuery or leave it as HTML.

My concerns are loading time as well as code simplification.

Code:
<div>
	<a href="#">A</a>
	<a href="#">B</a>
	<a href="#">C</a>
	<a href="#">D</a>
	<a href="#">E</a>
	<a href="#">F</a>
	<a href="#">G</a>
	<a href="#">H</a>
	<a href="#">I</a>
	<a href="#">J</a>
	<a href="#">K</a>
	<a href="#">L</a>
	<a href="#">M</a>
	<a href="#">N</a>
	<a href="#">O</a>
	<a href="#">P</a>
	<a href="#">Q</a>
	<a href="#">R</a>
	<a href="#">S</a>
	<a href="#">T</a>
	<a href="#">U</a>
	<a href="#">V</a>
	<a href="#">W</a>
	<a href="#">X</a>
	<a href="#">Y</a>
	<a href="#">Z</a>
</div>
m2244 is offline   Reply With Quote
Old 02-08-2013, 04:54 PM   PM User | #2
niralsoni
Regular Coder

 
Join Date: Mar 2008
Location: London
Posts: 129
Thanks: 1
Thanked 31 Times in 31 Posts
niralsoni is an unknown quantity at this point
Well, as of now it would look fine, but when you are actually adding the items to it, you may face some problems.

Following snippet might help you in achieving same using JavaScript (you can replace a bit of code with jQuery)

Code:
<div id="glossary"></div>

<script type="text/javascript">
  function loadGlossary(id) {
    var obj = document.getElementById(id), temp;
    for(var i = 65; i <=90; i++) {
      temp = document.createElement('A');
      temp.innerHTML = '&#'+i;
      temp.href = '#';
      obj.appendChild(temp);
      temp = document.createTextNode(' | ');
      obj.appendChild(temp);
    }
  }
  loadGlossary('glossary');
</script>
niralsoni is offline   Reply With Quote
Old 02-08-2013, 08:04 PM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
One thing to remember is that not everyone has JavaScript. JavaScript should only be used to add features to a web page that make it easier to use - not to provide the basic functioning that the page is there for.

If you want to generate that code instead of having to have it all hard coded then generate it using a server side language. That way you have the benefit of it being program generated AND everyone including those without JavaScript still sees the same HTML.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:36 PM.


Advertisement
Log in to turn off these ads.