Notices

Go Back   FileFront Forums > Main Forums > Tech Discussion > Programming 101

Remember Me?

Programming 101
Learn a range of programming languages from our resident experts! Ask questions and brush up your skills.

Like Tree1Likes
  • 1 Post By Mr. Mikey

Reply
 
LinkBack Thread Tools Display Modes
Old January 7th, 2014   #1
 
Arld's Avatar
 
Join Date: August 13th, 2008
6,928 posts, 395 likes.
Rep Power: 27
Arld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finest
Default [Solved!] Javascript: Using getElementById

I'm not exactly the best or most experienced user with JavaScript, so I'll go ahead and ask.

Basically, I want to inject some personal JavaScript for custom and client-side editing of the theme. This is necessary because of Jelsoft's horrible choice to use most styling inline instead of with IDs and classes.

So, I want to add my own class to certain nested elements, so I can then edit the CSS properly. However, it's not just a child of one element, but very deeply nested within a lot of other elements that don't have an ID either.

Ergo, usage of the getElementById is rather limited, because as far as I know, using:

Code:
document.getElementById('ID').children[x]
Is not exactly usable for more than a few children.

#

I'm looking for the following sequence of elements, whereas the last one is the one that's needs a new class:

Code:
div#posts > div > div.page > div > div > table.vbseo_like_postbit > tbody > tr > td
So I tried the following:

Code:
window.onload = function() {
	document.getElementById('posts > div > div.page > div > div > tbody > tr > td').className = 'arldEdit';
};
To no avail. Any clue?

Previously known as Graeme
Intel® Core™ i5-4690K @ 3.50GHz (Quad-Core) | MSI® H97 Gaming 3 (MS-7918)
8GB DDR3 RAM | NVIDIA® GeForce GTX 770 2GB VRAM GDDR5
Talk to me, mika, on ArloriaNET -> #welcome | #gamefront | #jacoders | #winning

Last edited by Arld; January 7th, 2014 at 10:06 PM.
Arld is offline   Reply With Quote
Old January 7th, 2014   #2
Mikeylicious
 
Mr. Mikey's Avatar
 
Join Date: June 12th, 2008
Location: United Kingdom
Status: Mikeylicious
543 posts, 89 likes.
Rep Power: 16
Mr. Mikey has a powerful reputationMr. Mikey has a powerful reputationMr. Mikey has a powerful reputationMr. Mikey has a powerful reputationMr. Mikey has a powerful reputationMr. Mikey has a powerful reputation
Default Re: Javascript: Using getElementById

Can't you use .childNodes.item(x).nodeValue ? if I remember correctly.

Either that or try the lowest class on the chain - so for this one will be vbseo_like_postbit

Also really? There are no ID's available? Le sigh.
Mr. Mikey is offline   Reply With Quote
Old January 7th, 2014   #3
 
Arld's Avatar
 
Join Date: August 13th, 2008
6,928 posts, 395 likes.
Rep Power: 27
Arld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finestArld is Gaming Forums’ finest
Default Re: Javascript: Using getElementById

Solved by now. Thanks though.

Turns out [with the help of Sheep & Cat] that I've been using the wrong approach. document.querySelectorAll() basically was what I needed. I then had to loop through its results, considering what is being returned is a NodeList (basically an array).

PHP Code:
var idx;
var 
listSignatureBit document.querySelectorAll('.vbseo_like_postbit td[valign="bottom"]');

for(
idx 0idx listSignatureBit.length; ++idx) {
    
listSignatureBit[idx].classList.add('ArldEdit');  


Previously known as Graeme
Intel® Core™ i5-4690K @ 3.50GHz (Quad-Core) | MSI® H97 Gaming 3 (MS-7918)
8GB DDR3 RAM | NVIDIA® GeForce GTX 770 2GB VRAM GDDR5
Talk to me, mika, on ArloriaNET -> #welcome | #gamefront | #jacoders | #winning

Last edited by Arld; January 7th, 2014 at 10:08 PM.
Arld is offline   Reply With Quote
Old January 9th, 2014   #4
Banned
El Bano
 
Tango Protocol's Avatar
 
Join Date: July 18th, 2003
Status: Available
3,377 posts, 35 likes.
Rep Power: 0
Tango Protocol - yes, we love youTango Protocol - yes, we love youTango Protocol - yes, we love youTango Protocol - yes, we love youTango Protocol - yes, we love youTango Protocol - yes, we love youTango Protocol - yes, we love youTango Protocol - yes, we love youTango Protocol - yes, we love youTango Protocol - yes, we love youTango Protocol - yes, we love you
Default Re: Javascript: Using getElementById

Ever consider using jQuery?

Code:
$('.vbseo_like_postbit td[valign="bottom"]').each(function(key, value) {
          $(value).addClass('arldEdit');
});

[CENTER]
[url="http://raptr.com/knippy?src=em_smforum"][img]http://raptr.com/badge/b69bb5ce84374c997d571b1dd95aa3ae/fss.png[/img][/url]

[URL="http://forums.filefront.com/member.php?u=108795"][COLOR=darkorange]Crazy Wolf[/COLOR][/URL] is a sexy beast.
[/center]
Tango Protocol is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7.







   
 





This site is part of the Defy Media Gaming network

The best serving of video game culture, since 2001. Whether you're looking for news, reviews, walkthroughs, or the biggest collection of PC gaming files on the planet, Game Front has you covered. We also make no illusions about gaming: it's supposed to be fun. Browse gaming galleries, humor lists, and honest, short-form reporting. Game on!

FileFront Forums - Terms of Service - Top
Theme Selection
Copyright © 2002-2016 Game Front. All rights reserved. Powered by vBulletin®
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Forum Theme by Danny King (FileTrekker), Sheepeep & Graeme(rs)
RSS Feed Widget by FeedWind