Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts

    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,
    Last edited by WolfShade; 10-08-2012 at 05:51 PM.
    ^_^

    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".

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,700
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    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).

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Worked like a charm.

    Thanks, VIPStephan!

    (I tried adding to your reputation, but it wouldn't let me.)
    Last edited by WolfShade; 10-08-2012 at 06:10 PM.
    ^_^

    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".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •