It is currently Thu May 08, 2025 1:26 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post Post subject: Useful JS Function
 
Offline
Godlike Poster
Godlike Poster
Years of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membership
User avatar

Joined: Sun Oct 16, 2005 9:42 am
Posts: 8798
Karma: 17

Location: Imagine in your mind a posh country club
Steam Login Name: azcn2503
Just thought I'd let you in on the MASTER FUNCTION! I include it all the time whenever I'm making any sort of DOM manipulation script. Put the following code in the head:

[code:1:eff19224a8]<script type="text/javascript"><!--
function grab(o){
return document.all?document.all[o]:document.getElementById?document.getElementById(o):"";
}
//--></script>[/code:1:eff19224a8]

Just use it in the following way:

If you wanted to change the width of the table with an id attribute of "table1", do the following:
[code:1:eff19224a8]grab("table1").style.width="600px";[/code:1:eff19224a8]

Or if you wanted to change the visibility of a certain element with an id attribute of "div3", do the following:
[code:1:eff19224a8]grab("div3").style.visibility="hidden";[/code:1:eff19224a8]

Handy bit of code.

_________________
Follow your heart and live the dream <3


Mon Nov 07, 2005 1:01 pm 
 Profile E-mail  
 
 Post Post subject:
 
Offline
Godlike Poster
Godlike Poster
Years of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membership
User avatar

Joined: Sun Oct 16, 2005 9:42 am
Posts: 8798
Karma: 17

Location: Imagine in your mind a posh country club
Steam Login Name: azcn2503
The above code works in all browsers.

Also, if you want to grab elements using the tag name, you can use the following code:

[code:1:e40b7c4b54]<script type="text/javascript"><!--
var objs=document.getElementsByTagName("tagName");
//--></script>[/code:1:e40b7c4b54]

This always returns an array, so even if there is only one of something, such as the body tag, you'll need to manipulate it like so...

[code:1:e40b7c4b54]document.getElementsByTagName("body")[0].style.backgroundColor='#000';[/code:1:e40b7c4b54]

Yay!

_________________
Follow your heart and live the dream <3


Mon Nov 07, 2005 1:14 pm 
 Profile E-mail  
 
 Post Post subject:
 
Offline
Top Gun (Admin)
Top Gun (Admin)
Years of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membership
User avatar

Joined: Mon Sep 12, 2005 6:48 am
Posts: 23428
Karma: 11

Location: This forum.
Steam Login Name: Skillers1990
I have no idea what that does! Could you enlighten me?

The 2nd and 3rd bits of code just seem like HTMl rewritten in javascript to me.

_________________
I was getting bored of this sig, and I realised I actually prefer small sigs ><
Join us on IRC! | TheSkillers.co.uk is under construction (still)!
Games: Steam | XFire | GFWL


Mon Nov 07, 2005 3:54 pm 
 Profile  
 
 Post Post subject:
 
Offline
Dominating
Dominating
Years of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membership

Joined: Mon Sep 12, 2005 6:29 pm
Posts: 399
Karma: 0
yeah, cud u put it on some webpage, let us see when and why we wud use it, cos since its comin from u its probably good

_________________
So the forums back in action


Mon Nov 07, 2005 4:59 pm 
 Profile E-mail  
 
 Post Post subject:
 
Offline
Godlike Poster
Godlike Poster
Years of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membership
User avatar

Joined: Sun Oct 16, 2005 9:42 am
Posts: 8798
Karma: 17

Location: Imagine in your mind a posh country club
Steam Login Name: azcn2503
Copy and paste the following code to make a page where the text is manipulated slightly.

[code:1:dc830a8928]<head>

<script type="text/javascript"><!--

function grab(o){
return document.all?document.all[o]:document.getElementById?document.getElementById(o):"";
}

//--></script>

</head>

<body>

<div style="width:100px;text-align:justify;" id="hello">

This is some placeholder text. I am here to make this page look pretty. I do nothing, basically. By clicking the button below, you will see
the effect of this super duper function, which is cross browser functional! Excellent, not much more to say...

</div>

<input type="button" value="+++" onclick="grab('hello').style.width='200px';" />
<input type="button" value="---" onclick="grab('hello').style.width='100px';" />

</body>[/code:1:dc830a8928]

_________________
Follow your heart and live the dream <3


Mon Nov 07, 2005 11:37 pm 
 Profile E-mail  
 
 Post Post subject:
 
Offline
Top Gun (Admin)
Top Gun (Admin)
Years of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membership
User avatar

Joined: Mon Sep 12, 2005 6:48 am
Posts: 23428
Karma: 11

Location: This forum.
Steam Login Name: Skillers1990
Ahhhh, I see. It allow the user to change the width of the table by pressing a button. Very useful.

_________________
I was getting bored of this sig, and I realised I actually prefer small sigs ><
Join us on IRC! | TheSkillers.co.uk is under construction (still)!
Games: Steam | XFire | GFWL


Tue Nov 08, 2005 7:51 am 
 Profile  
 
 Post Post subject:
 
Offline
Godlike Poster
Godlike Poster
Years of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membershipYears of membership
User avatar

Joined: Sun Oct 16, 2005 9:42 am
Posts: 8798
Karma: 17

Location: Imagine in your mind a posh country club
Steam Login Name: azcn2503
It's very handy. Works with almost everything in the document. Good for dynamically changing the class of something (CSS), like when you want to turn tab_default in to tab_active.

_________________
Follow your heart and live the dream <3


Tue Nov 08, 2005 9:27 am 
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Karma functions powered by Karma MOD © 2007, 2009 m157y