Javscript push() problem?

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

gamescoper

Established Member
Impact
1
i am trying to get all the headers (text in <h3> tags) in a webpage and i seem to be stuck on this, it all works fine until i try to put all the headers in one line

i would use some uber-cool javscript framework but GCSE ICT needs me to use javascript that has to be made by ME or else i have to go through each line and redocument millions of lines of code just to use one function

Code:
var n; 
var temp; 
var text = ["| "]; 
var titles=document.getElementsByTagName("h3"); 
for (n=0; n<titles.length; n++)
{ 
temp = titles[n].innertext; 
text.push(titles[n].innertext); 
text.push(" | "); 
}



p.s. please note that i am not great at javascript
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
So, the main task is to create an array with delimiters and contents of all h3 tags?

gamescoper said:
Code:
var n; 
[s]var temp;[/s] //do not need this
var text = ["| "]; 
var titles=document.getElementsByTagName("h3"); 
for (n=0; n<titles.length; n++)
{ 
[s]temp = titles[n].innertext;[/s] //do not need this
text.push(titles[n].inner[COLOR=Red][b]T[/b][/COLOR]ext); //case-sensitive!!!
text.push(" | "); 
}

Result will be an array something like this:
text[0] = "| "
text[1] = "text 1"
text[2] = " | "
text[3] = "text 2"
... (and so on)

If you need to create single line with all headers (with delimiters), you should rewrite your code:

Code:
var n;
var titles=document.getElementsByTagName("h3"); 
var text = "| ";
for (n=0; n<titles.length; n++)
{ 
	text += titles[n].innerText;
	text += " | ";
}

Now variable text will contain "| text1 | text 2 | ... text N | "
 
0
•••
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

Parking: find your domains by pasting a list
You can now paste a list of domain names into the search box at the top of the Parking menu. Put one name on each line. Your domain list...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back