Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

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 10-08-2012, 05:25 PM   PM User | #1
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 946
Thanks: 7
Thanked 97 Times in 97 Posts
WolfShade is an unknown quantity at this point
jQuery('#elemID') != document.getElementById('elemID')

Hey, everyone.

Help me to understand something.

I have a function that will take all the spans with a certain class ("jobStatus") and remove an additional class from it ("orange"). I call the function from a SELECT onchange (onchange="chgJobstatus(this);"). It's working great.

However, I'm trying to get it to run on page load, based upon the selected value (this is server-side dynamically generated.)

This will work:
Code:
$(document).ready(function(){
  chgJobstatus(document.getElementById("chgStatus"));
});
This will NOT work:
Code:
$(document).ready(function(){
  chgJobstatus(jQuery('#chgStatus'));
});
Doesn't jQuery('#id') do the same thing as document.getElementById('#id') ??

Thank you,
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

Last edited by WolfShade; 10-08-2012 at 05:51 PM..
WolfShade is online now   Reply With Quote
Old 10-08-2012, 05:36 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,602
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
document.getElementById() returns a DOM node and jQuery('#id') (or $('#id')) returns a jQuery object. I’m not JS guru enough to fully understand and explain that myself but you can turn a jQuery object into a DOM node by writing $('#id')[0] (the first item in the array of the object’s properties is the DOM node) and a DOM node into a jQuery object by wrapping it with the jQuery default function (jQuery(domNodeHere) or $(domNodeHere), respectively).
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 10-08-2012, 05:42 PM   PM User | #3
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 946
Thanks: 7
Thanked 97 Times in 97 Posts
WolfShade is an unknown quantity at this point
Since chgStatus is a select and the only node with that ID, all I have to do is append [0] to it, like so:

Code:
$(document).ready(function(){
 chgJobstatus(jQuery('#chgStatus')[0]); 
});
?
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is online now   Reply With Quote
Old 10-08-2012, 05:50 PM   PM User | #4
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 946
Thanks: 7
Thanked 97 Times in 97 Posts
WolfShade is an unknown quantity at this point
Worked like a charm.

Thanks, VIPStephan!

(I tried adding to your reputation, but it wouldn't let me.)
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

Last edited by WolfShade; 10-08-2012 at 06:10 PM..
WolfShade is online now   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:48 PM.


Advertisement
Log in to turn off these ads.