Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

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-07-2013, 04:09 PM   PM User | #1
thadeus
New to the CF scene

 
Join Date: Oct 2010
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
thadeus is an unknown quantity at this point
JS selector engine - array issue

Hello All,

I am trying to build a small selector engine in order to detect the number of specific html tags, but I am having trouble in storing the number of the found tags in an array and afterwards printing them in the html..

Can someone please help me out? You can find the code below.

Code:
  var seltags = function (select) {
  var nodes = [];
  
  var div = document.getElementsByTagName('div');
  var divlen = div.length;
  document.write(divlen+nodes[0]+' DIVs. ');
  
  var img = document.getElementsByTagName('img');
  var imglen = img.length;
  document.write(imglen+nodes[1]+' IMGs. ');
  
  var inp = document.getElementsByTagName('input');
  var inplen = inp.length;
  document.write(inplen+nodes[2]+' INPUTs. ');
  
  for (var i=0, l=var divlen; i<l, i++){
      
  };

  //alert(len);

  return nodes;
}
Now I need some guidance on how to proceed on this because im quite confused and lost.. Im not that experienced in JavaScript so im really struggling.. Any help would be much appreciated.

Thank you in advance.
thadeus is offline   Reply With Quote
Old 02-07-2013, 04:37 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
And what is your exact idea behind designing a new "Selector Engine" that too without experienced in JavaScript ??
niralsoni is offline   Reply With Quote
Users who have thanked niralsoni for this post:
thadeus (02-07-2013)
Old 02-07-2013, 04:53 PM   PM User | #3
thadeus
New to the CF scene

 
Join Date: Oct 2010
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
thadeus is an unknown quantity at this point
Experience kind Sir.
thadeus is offline   Reply With Quote
Old 02-08-2013, 11:04 AM   PM User | #4
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, I appreciate your affort. But the thing is without having proper knowledge of any programming language, you can't just start implementing your idea.

I would prefer you to start understanding the basics first, and then come with a clear picture of what your exact problem is.

Lets investigate what you have provided -

1) you defined a variable nodes as an array.

2) then you are trying to access nodes[0], nodes[1], and nodes[2] that too variable nodes without any values stored.

3) the problem in your for loop syntax (as highlighted in red)-
for (var i=0, l=var divlen; i<l, i++){
}

It should be
for(var i = 0, l = divlen; i < l; i++) {
}

4) No semicolon ( ; ) after end of for loop

5) The argument select passed in the function is never used, and the function is returning the empty array nodes.

so, logically, there is no use of this function.
niralsoni 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 03:24 PM.


Advertisement
Log in to turn off these ads.