CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   DOM and JSON scripting (http://www.codingforums.com/forumdisplay.php?f=15)
-   -   JS selector engine - array issue (http://www.codingforums.com/showthread.php?t=287261)

thadeus 02-07-2013 04:09 PM

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.

niralsoni 02-07-2013 04:37 PM

And what is your exact idea behind designing a new "Selector Engine" that too without experienced in JavaScript ??

thadeus 02-07-2013 04:53 PM

Experience kind Sir.

niralsoni 02-08-2013 11:04 AM

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.


All times are GMT +1. The time now is 09:50 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.